Skip Menu |

This queue is for tickets about the App-Daemon CPAN distribution.

Report information
The Basics
Id: 51066
Status: resolved
Priority: 0/
Queue: App-Daemon

People
Owner: Nobody in particular
Requestors: PENFOLD [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.07
Fixed in: (no value)



Subject: closing STDOUT/ERR in detach redirects warn()
detach() closes STDOUT, STDERR rather than redirecting them to /dev/null As a result, the following code snippet has a rather surprising effect: -------------- use strict; use warnings; use App::Daemon qw/daemonize/; daemonize(); use Test::Fork; use IO::Socket; fork_ok( 1, sub { my $sock = new IO::Socket::INET ( LocalHost => 'localhost', LocalPort => 9001, Proto => 'tcp', Listen => 1, Reuse => 1, ); open LOG,">/tmp/weirdlog"; ok ($sock, "Created listener ok"); my $accept = $sock->accept(); while (<$accept>) { print LOG ">>>2: $_"; } } ); sleep 1; my $sock = IO::Socket::INET->new( PeerHost => 'localhost', PeerPort => 9001, Proto => 'TCP', ); my $d; my $data = "foo: $d\n"; # this will generate warning "Use of uninitialized value $d..." print $sock $data; ------- The warning from the unitialized variable ends up being sent down the socket!
On Tue Nov 03 03:45:19 2009, PENFOLD wrote: Show quoted text
> detach() closes STDOUT, STDERR rather than redirecting them to > /dev/null > > As a result, the following code snippet has a rather surprising > effect:
Horrible snippet, I know - basically the problem is that warn will send to whatever re-uses STDERR's filedescriptor herewith a patch: --- App-Daemon-0.07/Daemon.pm 2009-10-08 17:04:07.000000000 +0100 +++ App-Daemon-0.07.new/Daemon.pm 2009-11-03 11:39:12.000000000 +0000 @@ -183,10 +183,10 @@ user_switch(); } - # close std file descriptors - close(STDIN); - close(STDOUT); - close(STDERR); +  # redirect standard file descriptors to devnull + open STDIN, '/dev/null'; + open STDOUT, '>>/dev/null'; + open STDERR, '>>/dev/null'; }
Thanks, applied: http://github.com/mschilli/app-daemon/commit/cbe1f84398af67ddae48d1b86f83e54734c7f39d ... and released as App-Daemon-0.08 to CPAN.