added support to logging on the standard file descriptors #268

This commit is contained in:
Jordi Sanfeliu 2020-09-02 11:41:16 +02:00
parent ef0908ca3c
commit 80217b1420
1 changed files with 8 additions and 3 deletions

View File

@ -95,12 +95,17 @@ sub HUP_handler {
}
sub daemonize {
open(STDIN, "< /dev/null") || die "Can't read /dev/null: $!";
open(STDOUT, ">> $config{log_file}") || die "Can't write to LOG: $!";
if($config{log_file}) {
open(STDIN, "< /dev/null") || die "Can't read /dev/null: $!";
open(STDOUT, ">> $config{log_file}") || die "Can't write to LOG: $!";
}
umask(022) || die "Unable to umask 022: $!";
exit if fork(); # parent exits
(setsid() != -1) || die "Can't start a new session: $!";
open(STDERR, ">> $config{log_file}") || die "Can't write to LOG: $!";
if($config{log_file}) {
open(STDERR, ">> $config{log_file}") || die "Can't write to LOG: $!";
}
}
sub usage {