Is anyone aware of a problem with dup-ing a fd to stdin? Attached is a module I'm using to get the output of an exec-ed command.
When I call this module from a script it gives the right output. When I call this from a Mason module, I get "0 0 0" (as if no input was read). When I call this from the single threaded server (using -X), the request hangs, and it seems to be taking input from my shell (the shell that invoked 'httpd -X'). If I run strace on httpd, instead of a "dup2(X, 0)" call, I see a single argument call "dup(X)"; the dup to stdout is a dup2() call. It seems that someone is intercepting the dup2(X, 0) call and treating it as a single argument dup() call. My platform: Apache: 1.3.22 mod_perl: 1.26 Linux: Redhat 7.2/Intel
use strict; use FileHandle; package Test; sub test { my ($R, $W) = open_proc([ "/usr/bin/wc" ]); print $W "this is a test\n"; close($W); my $buf; while (<$R>) { $buf .= $_; } close($R); $buf; } sub open_proc { my $args = shift; my ($R1, $W1, $R2, $W2); ($R1, $W1) = FileHandle::pipe or die "unable to create pipes"; ($R2, $W2) = FileHandle::pipe or die "unable to create pipes"; my $pid; unless (defined($pid = fork)) { die "unable to fork: $!"; } elsif ($pid == 0) { # child time; open(STDIN, "<&".fileno($R1)) or die "unable to dup STDIN: $!"; time; open(STDOUT, ">&".fileno($W2)) or die "unable to dup STDOUT: $!"; close($W1); close($R2); exec(@$args) or die "unable to exec ".$args->[0].": $!"; } ($R2, $W1, $pid); }