X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FDaemonize%2FCore.pm;h=6c3e07a3f18ff4cc8b8bff5c2a90041d81d752c7;hb=df3c463b810bb63cbf295a8e822dc887844b9a0b;hp=5447f63a782f15e608b6912856babef5a6ed7c4c;hpb=4327fe988c1c6e363f8e8a6eeda373e1950fcd17;p=gitmo%2FMooseX-Daemonize.git diff --git a/lib/MooseX/Daemonize/Core.pm b/lib/MooseX/Daemonize/Core.pm index 5447f63..6c3e07a 100644 --- a/lib/MooseX/Daemonize/Core.pm +++ b/lib/MooseX/Daemonize/Core.pm @@ -51,12 +51,14 @@ sub daemon_detach { chdir '/'; # change to root directory umask 0; # clear the file creation mask - # get the max numnber of possible file descriptors - my $openmax = POSIX::sysconf( &POSIX::_SC_OPEN_MAX ); - $openmax = 64 if !defined($openmax) || $openmax < 0; + unless ($options{dont_close_all_files}) { + # get the max numnber of possible file descriptors + my $openmax = POSIX::sysconf( &POSIX::_SC_OPEN_MAX ); + $openmax = 64 if !defined($openmax) || $openmax < 0; - # close them all - POSIX::close($_) foreach (0 .. $openmax); + # close them all + POSIX::close($_) foreach (0 .. $openmax); + } # fixup STDIN ... @@ -77,7 +79,7 @@ sub daemon_detach { # fixup STDERR ... if (my $stderr_file = $ENV{MX_DAEMON_STDERR}) { - open STDERR, ">", "ERR.txt" + open STDERR, ">", $stderr_file or confess "Could not redirect STDERR to $stderr_file : $!"; } else { @@ -203,6 +205,8 @@ directory then simply change it later in your daemons code. =item Closes all open file descriptors. +See below for information on how to change this part of the process. + =item Reopen STDERR, STDOUT & STDIN to /dev/null This behavior can be controlled slightly though the MX_DAEMON_STDERR @@ -226,6 +230,12 @@ found above, and by Googling "double fork daemonize". If you the double-fork behavior off, you might want to enable the I behavior in the C method. +=item I + +Setting this option to true will cause it to skip closing all the +filehandles, this is useful if you are opening things like sockets +and such in the pre-fork. + =back B @@ -337,7 +347,7 @@ Stevan Little C<< >> =head1 LICENCE AND COPYRIGHT -Copyright (c) 2007, Chris Prather C<< >>. All rights +Copyright (c) 2007-2008, Chris Prather C<< >>. All rights reserved. Portions heavily borrowed from L which is copyright Earl Hood.