summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2011-06-05 15:01:13 +0200
committerNicholas Clark <nick@ccl4.org>2011-06-11 08:48:13 +0200
commitf598f6deabaea2ddb1fe1242577961f817614c8b (patch)
tree449e006f706d9508e56198c746d1eb385ed1f254 /ext
parent1ede20e6f8f8e8421610e16743bfed46dc90efb0 (diff)
downloadperl-f598f6deabaea2ddb1fe1242577961f817614c8b.tar.gz
Add debug code to test IPC::Open3::spawn_with_handles() on *nix.
This allows testing of the (normally) Win32 and OS/2 specific code paths in IPC::Open3::open3().
Diffstat (limited to 'ext')
-rw-r--r--ext/IPC-Open3/lib/IPC/Open3.pm25
1 files changed, 23 insertions, 2 deletions
diff --git a/ext/IPC-Open3/lib/IPC/Open3.pm b/ext/IPC-Open3/lib/IPC/Open3.pm
index b1acfd08c8..4513fffc3a 100644
--- a/ext/IPC-Open3/lib/IPC/Open3.pm
+++ b/ext/IPC-Open3/lib/IPC/Open3.pm
@@ -194,7 +194,8 @@ sub xfileno {
return fileno $_[0];
}
-use constant DO_SPAWN => $^O eq 'os2' || $^O eq 'MSWin32';
+use constant FORCE_DEBUG_SPAWN => 0;
+use constant DO_SPAWN => $^O eq 'os2' || $^O eq 'MSWin32' || FORCE_DEBUG_SPAWN;
sub _open3 {
local $Me = shift;
@@ -400,13 +401,33 @@ sub spawn_with_handles {
unless ($^O eq 'MSWin32') {
# Stderr may be redirected below, so we save the err text:
foreach $fd (@$close_in_child) {
+ next unless fileno $fd;
fcntl($fd, Fcntl::F_SETFD(), 1) or push @errs, "fcntl $fd: $!"
unless $saved{fileno $fd}; # Do not close what we redirect!
}
}
unless (@errs) {
- $pid = eval { system 1, @_ }; # 1 == P_NOWAIT
+ if (FORCE_DEBUG_SPAWN) {
+ pipe my $r, my $w or die "Pipe failed: $!";
+ $pid = fork;
+ die "Fork failed: $!" unless defined $pid;
+ if (!$pid) {
+ { no warnings; exec @_ }
+ print $w 0 + $!;
+ close $w;
+ require POSIX;
+ POSIX::_exit(255);
+ }
+ close $w;
+ my $bad = <$r>;
+ if (defined $bad) {
+ $! = $bad;
+ undef $pid;
+ }
+ } else {
+ $pid = eval { system 1, @_ }; # 1 == P_NOWAIT
+ }
push @errs, "IO::Pipe: Can't spawn-NOWAIT: $!" if !$pid || $pid < 0;
}