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