From: Stevan Little Date: Fri, 30 Nov 2007 02:39:44 +0000 (+0000) Subject: no more Proc::Daemon X-Git-Tag: 0_06~21 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ea9485d8cc815a443d6bb844858156d1fdb65a42;p=gitmo%2FMooseX-Daemonize.git no more Proc::Daemon --- diff --git a/Makefile.PL b/Makefile.PL index 25c4101..7acfffd 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -8,7 +8,6 @@ all_from 'lib/MooseX/Daemonize.pm'; # Specific dependencies build_requires 'Test::More' => 0; -requires 'Proc::Daemon' => 0; requires 'MooseX::Getopt' => 0; requires 'Moose' => 0.20; diff --git a/lib/MooseX/Daemonize.pm b/lib/MooseX/Daemonize.pm index d3a8739..94268b5 100644 --- a/lib/MooseX/Daemonize.pm +++ b/lib/MooseX/Daemonize.pm @@ -152,18 +152,18 @@ $_kill = sub { # Try SIGINT ... 2s ... SIGTERM ... 2s ... SIGKILL ... 3s ... UNDEAD! for ( [ 2, $timeout ], [15, $timeout], [9, $timeout * 1.5] ) { - my ($signal, $timeout) = @$_; - $timeout = int $timeout; - - CORE::kill($signal, $pid); - - last unless CORE::kill 0 => $pid or $!{EPERM}; - - while ($timeout) { - sleep(1); + my ($signal, $timeout) = @$_; + $timeout = int $timeout; + + CORE::kill($signal, $pid); + last unless CORE::kill 0 => $pid or $!{EPERM}; - $timeout--; - } + + while ($timeout) { + sleep(1); + last unless CORE::kill 0 => $pid or $!{EPERM}; + $timeout--; + } } return unless ( CORE::kill 0 => $pid or $!{EPERM} ); diff --git a/lib/MooseX/Daemonize/Core.pm b/lib/MooseX/Daemonize/Core.pm index dbf892e..27e0dd6 100644 --- a/lib/MooseX/Daemonize/Core.pm +++ b/lib/MooseX/Daemonize/Core.pm @@ -4,7 +4,7 @@ use Moose::Role; our $VERSION = 0.01; -use Proc::Daemon; +use POSIX (); has is_daemon => ( isa => 'Bool', @@ -12,8 +12,28 @@ has is_daemon => ( default => sub { 0 }, ); -sub daemon_fork { Proc::Daemon::Fork } -sub daemon_detach { Proc::Daemon::Init } +sub daemon_fork { fork } +sub daemon_detach { + # ignore these signals + for (qw(TSTP TTIN TTOU PIPE POLL STOP CONT CHLD)) { + $SIG{$_} = 'IGNORE' if (exists $SIG{$_}); + } + + POSIX::setsid; # set session id + 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; + + # close them all + POSIX::close($_) foreach (0 .. $openmax); + + open(STDIN, "+>/dev/null"); + open(STDOUT, "+>&STDIN"); + open(STDERR, "+>&STDIN"); +} sub daemonize { my ($self) = @_;