X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FTak%2FDaemon%2FDaemonService.pm;fp=lib%2FTak%2FDaemon%2FDaemonService.pm;h=f50731456634e71c7c21873323756fb51634030a;hb=944cf4b4d8702aab7a07d57cf63b665fc207f8be;hp=80f0f08ea26ad95181be411631c5ab36d796b84d;hpb=baea9bdae94b3880fdb1a1788ed54a7aec15e2ad;p=scpubgit%2FTak-Daemon.git diff --git a/lib/Tak/Daemon/DaemonService.pm b/lib/Tak/Daemon/DaemonService.pm index 80f0f08..f507314 100644 --- a/lib/Tak/Daemon/DaemonService.pm +++ b/lib/Tak/Daemon/DaemonService.pm @@ -19,11 +19,6 @@ sub handle_daemonize { fork and exit; POSIX::setsid or die "Couldn't setsid: $!"; fork and exit; - close STDERR; - open STDERR, '>', '/dev/null' or die "Couldn't re-open stderr: $!"; - Log::Contextual::set_logger( # there's no NullLogger? I thought I wrote one - Log::Contextual::SimpleLogger->new({ levels => [] }) - ); return 'done'; } @@ -34,6 +29,17 @@ sub handle_become_successor { # because this is funnier than "no warnings 'once'". Also because # I don't have to stop and think "what else is in this lexical scope?" $Tak::STDIOSetup::Next = $Tak::STDIOSetup::Next = sub { + + # have to do this here because when we're being set up stderr may + # be redirected (e.g. because we're in an ->do under a repl) - and + # plus it leaves logging running until the last possible minute, + # which is almost certainly a win anyway. + close STDERR; + open STDERR, '>', '/dev/null' or die "Couldn't re-open stderr: $!"; + Log::Contextual::set_logger( # there's no NullLogger? I thought I wrote one + Log::Contextual::SimpleLogger->new({ levels => [] }) + ); + my $x = $self; # close over while evading void context warnings $0 = 'tak-daemon-node'; Tak->loop_until($done);