Looking at the source code of Proc::Daemon, the relevant code has potential for failures but doesn't check the results:
sub Init {
my $oldmode = shift || 0;
my($pid, $sess_id, $i);
## Fork and exit parent
if ($pid = Fork) { exit 0; }
## Detach ourselves from the terminal
croak "Cannot detach from controlling terminal"
unless $sess_id = POSIX::setsid();
## Prevent possibility of acquiring a controling terminal
if (!$oldmode) {
$SIG{'HUP'} = 'IGNORE';
if ($pid = Fork) { exit 0; }
}
## Change working directory
chdir "/";
## Clear file creation mask
umask 0;
## Close open file descriptors
foreach $i (0 .. OpenMax) { POSIX::close($i); }
## Reopen stderr, stdout, stdin to /dev/null
open(STDIN, "+>/dev/null");
open(STDOUT, "+>&STDIN");
open(STDERR, "+>&STDIN");
$oldmode ? $sess_id : 0;
}
There are a couple of possibilities for you to check:
- The code closes all files currently open. From how I understand Log::Log4Perl::FileAppender, it opens the file once and then tries to use the filehandle it got from that. So maybe you need to reopen your log files after having become a daemon.
- The code sets the umask to 0, so you might need to reset it in your daemon code to some sensible value if you're trying to create new files
- The code resets SIGHUP, so whatever you're doing with SIGHUP might conflict with that.
- The Proc::Daemon code doesn't check for the result of chdir("/") - maybe you are not allowed to set your directory to / - this should be checked but is likely not the cause of your problems.
For more debugging information, you should maybe reopen STDERR to a log file to which you warn (instead of using Log::Log4Perl) - I expect some print to closed file handle messages here.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.