From: Matt S Trout Date: Tue, 6 Dec 2011 23:00:40 +0000 (+0000) Subject: move STDERR re-opening to a better place X-Git-Tag: v0.001001~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=944cf4b4d8702aab7a07d57cf63b665fc207f8be;p=scpubgit%2FTak-Daemon.git move STDERR re-opening to a better place --- 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);