summaryrefslogtreecommitdiff
path: root/ext/IPC-Open3
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2011-06-06 19:19:29 +0200
committerNicholas Clark <nick@ccl4.org>2011-06-11 08:48:16 +0200
commitf2412f8992265c5e91329c250ba4711946a5e321 (patch)
treebabac6590eedf9376939bb9b9455a0573e9f3e5f /ext/IPC-Open3
parentb38d735f00806962171b7b16c49e3fd64075ecb9 (diff)
downloadperl-f2412f8992265c5e91329c250ba4711946a5e321.tar.gz
Use $handles[2]{dup_of_out} for the special case code for shared STD{OUT,ERR}.
As C<dup_of_out> is never set on the other two members of @handles, this will allow code simplification.
Diffstat (limited to 'ext/IPC-Open3')
-rw-r--r--ext/IPC-Open3/lib/IPC/Open3.pm11
1 files changed, 6 insertions, 5 deletions
diff --git a/ext/IPC-Open3/lib/IPC/Open3.pm b/ext/IPC-Open3/lib/IPC/Open3.pm
index 9ea0112223..c57a306ed2 100644
--- a/ext/IPC-Open3/lib/IPC/Open3.pm
+++ b/ext/IPC-Open3/lib/IPC/Open3.pm
@@ -229,6 +229,7 @@ sub _open3 {
}
$handles[2]{parent} ||= $handles[1]{parent};
+ $handles[2]{dup_of_out} = $handles[1]{parent} eq $handles[2]{parent};
$handles[0]{dup} = ($handles[0]{parent} =~ s/^[<>]&//);
$handles[1]{dup} = ($handles[1]{parent} =~ s/^[<>]&//);
@@ -242,7 +243,7 @@ sub _open3 {
xpipe $handles[0]{open_as}, $handles[0]{parent} if !$handles[0]{dup};
xpipe $handles[1]{parent}, $handles[1]{open_as} if !$handles[1]{dup};
- xpipe $handles[2]{parent}, $handles[2]{open_as} if !$handles[2]{dup} && $handles[2]{parent} ne $handles[1]{parent};
+ xpipe $handles[2]{parent}, $handles[2]{open_as} if !$handles[2]{dup} && !$handles[2]{dup_of_out};
my $kidpid;
if (!DO_SPAWN) {
@@ -261,7 +262,7 @@ sub _open3 {
# If she wants to dup the kid's stderr onto her stdout I need to
# save a copy of her stdout before I put something else there.
- if ($handles[1]{parent} ne $handles[2]{parent} && $handles[2]{dup}
+ if (!$handles[2]{dup_of_out} && $handles[2]{dup}
&& xfileno($handles[2]{parent}) == fileno \*STDOUT) {
my $tmp = gensym;
xopen($tmp, '>&', $handles[2]{parent});
@@ -280,7 +281,7 @@ sub _open3 {
xclose $handles[1]{parent};
xopen \*STDOUT, ">&=", fileno $handles[1]{open_as};
}
- if ($handles[1]{parent} ne $handles[2]{parent}) {
+ if (!$handles[2]{dup_of_out}) {
if ($handles[2]{dup}) {
xopen \*STDERR, '>&', $handles[2]{parent}
if fileno \*STDERR != xfileno($handles[2]{parent});
@@ -342,7 +343,7 @@ sub _open3 {
} else {
push @close, \*{$handles[1]{parent}}, $handles[1]{open_as};
}
- if ($handles[1]{parent} ne $handles[2]{parent}) {
+ if (!$handles[2]{dup_of_out}) {
if ($handles[2]{dup}) {
$handles[2]{open_as} = $handles[2]{parent} =~ /\A[0-9]+\z/ ? $handles[2]{parent} : \*{$handles[2]{parent}};
push @close, $handles[2]{open_as};
@@ -361,7 +362,7 @@ sub _open3 {
xclose $handles[0]{open_as} if !$handles[0]{dup};
xclose $handles[1]{open_as} if !$handles[1]{dup};
- xclose $handles[2]{open_as} if !$handles[2]{dup} && $handles[1]{parent} ne $handles[2]{parent};
+ xclose $handles[2]{open_as} if !$handles[2]{dup} && !$handles[2]{dup_of_out};
# If the write handle is a dup give it away entirely, close my copy
# of it.
xclose $handles[0]{parent} if $handles[0]{dup};