NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Daemonizing processes in NetBSD



W dniu 17.02.2021 o 21:56, Edgar Pettijohn pisze:
If you have perl available the following should do what you
need. Wouldn't be too difficult to write something similar
in C as well.

#!/usr/bin/env perl

use strict;
use warnings;

use POSIX qw//;

sub daemonize {
	defined (my $pid = fork()) or die "Can't fork: $!";
	exit if $pid;
	defined (my $ppid = fork()) or die "Can't fork: $!";
	exit if $ppid;
	chdir "/" or die "Can't chdir '/': $!";
	POSIX::setsid or die "Can't start new session: $!";
}

daemonize();

eval {
	my @cmd = @ARGV;
	exec @cmd;
};

warn $@ if $@;

exit;


Thank you all for suggestions. Available software is in pkgsrc to do just this in sysutils/daemond and sysutils/daemonize but I won't use it for the startup script. I will be asking the upstream project to include proper behavior or command line switch.

If you're not familiar with AdGuardHome I encourage you to test it from wip/adguardhome. It is similar to pi-hole: provides a DNS level blocker (and DHCP server if you require it, but it's optional) with statistics, logs and auto blocklist update. At my home it manages to block ~20% of DNS requests and at my parent's home it's more like ~35%. Since it is a list-based blocker (though it has some unique features to test domains with AdGuard systems if you wish to do so) it is prone to false positives but that heavily depends on your usage pattern and blocklists you enable.

Regards
--
Bartek Krawczyk


Home | Main Index | Thread Index | Old Index