Subject: | POE::Wheel::Run child STD* redirection checks |
Using POE v0.29, POE::Wheel::Run v1.58, perl v5.6.1, RedHat 7.3
On line 375:
open( STDIN, "<&" . fileno($stdin_read) )
A problem occurs here if STDIN (and a bit later STDOUT or STDERR) is closed prior to calling new(). The fileno of STDIN is undefined and not guaranteed to be 0, especially if other files are opened in the mean time. I've attached a patch that dies (or should it just carp?) if the open does not result in STDIN's fileno equalling STDIN_FILENO (from POSIX).
This should only happen if someone does something silly (which I was), but maybe it'll make tracking down the problem a bit less painful.
-JayKim
*** Run.pm.orig Thu Dec 9 14:38:43 2004
--- Run.pm Thu Dec 9 15:00:11 2004
***************
*** 10,16 ****
use Carp qw(carp croak);
use POSIX qw(
sysconf _SC_OPEN_MAX ECHO ICANON IEXTEN ISIG BRKINT ICRNL INPCK
! ISTRIP IXON CSIZE PARENB OPOST TCSANOW
);
use POE qw( Wheel Pipe::TwoWay Pipe::OneWay Driver::SysRW Filter::Line );
--- 10,16 ----
use Carp qw(carp croak);
use POSIX qw(
sysconf _SC_OPEN_MAX ECHO ICANON IEXTEN ISIG BRKINT ICRNL INPCK
! ISTRIP IXON CSIZE PARENB OPOST TCSANOW STDIN_FILENO STDOUT_FILENO STDERR_FILENO
);
use POE qw( Wheel Pipe::TwoWay Pipe::OneWay Driver::SysRW Filter::Line );
***************
*** 374,388 ****
--- 374,394 ----
# Redirect STDIN from the read end of the stdin pipe.
open( STDIN, "<&" . fileno($stdin_read) )
or die "can't redirect STDIN in child pid $$: $!";
+ fileno(STDIN) == STDIN_FILENO
+ or die "child's STDIN filehandle does not have fileno of ".STDIN_FILENO;
# Redirect STDOUT to the write end of the stdout pipe.
open( STDOUT, ">&" . fileno($stdout_write) )
or die "can't redirect stdout in child pid $$: $!";
+ fileno(STDOUT) == STDOUT_FILENO
+ or die "child's STDOUT filehandle does not have fileno of ".STDOUT_FILENO;
# Redirect STDERR to the write end of the stderr pipe. If the
# stderr pipe's undef, then we use STDOUT.
open( STDERR, ">&" . fileno($stderr_write) )
or die "can't redirect stderr in child: $!";
+ fileno(STDERR) == STDERR_FILENO
+ or die "child's STDERR filehandle does not have fileno of ".STDERR_FILENO;
# Make STDOUT and/or STDERR auto-flush.
select STDERR; $| = 1;