summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorGurusamy Sarathy <gsar@cpan.org>2002-07-15 23:58:49 +0000
committerGurusamy Sarathy <gsar@cpan.org>2002-07-15 23:58:49 +0000
commit4e6dfe7129c097c1c55e03c2282efd9f7d35d6ff (patch)
treeb0aa8e99101b9ec161b1594d8ab2594f3841e2c5 /util.c
parent96dad7c660b4ae9d8a81932e311d775c593acb10 (diff)
downloadperl-4e6dfe7129c097c1c55e03c2282efd9f7d35d6ff.tar.gz
change#16528 merged the fix for my_popen() but missed my_popen_list()
which had the same code (and bugs) duplicated; add changes#16329,16331 into my_popen_list() p4raw-link: @16528 on //depot/perl: b5ac89c3e91fc5e73ab09acd099240e5aaa213a5 p4raw-link: @16331 on //depot/maint-5.6/perl: 821302ef08e28e13ed846e63b71b1a8e0bd6e09a p4raw-link: @16329 on //depot/maint-5.6/perl: 5676c1b12073c1e0625a9800fba3bbcb4a2e99c8 p4raw-id: //depot/perl@17565
Diffstat (limited to 'util.c')
-rw-r--r--util.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/util.c b/util.c
index 623c44cf81..e42efe3f11 100644
--- a/util.c
+++ b/util.c
@@ -1962,6 +1962,7 @@ Perl_my_popen_list(pTHX_ char *mode, int n, SV **args)
while ((pid = PerlProc_fork()) < 0) {
if (errno != EAGAIN) {
PerlLIO_close(p[This]);
+ PerlLIO_close(p[that]);
if (did_pipes) {
PerlLIO_close(pp[0]);
PerlLIO_close(pp[1]);
@@ -1976,8 +1977,6 @@ Perl_my_popen_list(pTHX_ char *mode, int n, SV **args)
#undef THAT
#define THIS that
#define THAT This
- /* Close parent's end of _the_ pipe */
- PerlLIO_close(p[THAT]);
/* Close parent's end of error status pipe (if any) */
if (did_pipes) {
PerlLIO_close(pp[0]);
@@ -1990,7 +1989,11 @@ Perl_my_popen_list(pTHX_ char *mode, int n, SV **args)
if (p[THIS] != (*mode == 'r')) {
PerlLIO_dup2(p[THIS], *mode == 'r');
PerlLIO_close(p[THIS]);
+ if (p[THAT] != (*mode == 'r')) /* if dup2() didn't close it */
+ PerlLIO_close(p[THAT]); /* close parent's end of _the_ pipe */
}
+ else
+ PerlLIO_close(p[THAT]); /* close parent's end of _the_ pipe */
#if !defined(HAS_FCNTL) || !defined(F_SETFD)
/* No automatic close - do it by hand */
# ifndef NOFILE
@@ -2012,8 +2015,6 @@ Perl_my_popen_list(pTHX_ char *mode, int n, SV **args)
}
/* Parent */
do_execfree(); /* free any memory malloced by child on fork */
- /* Close child's end of pipe */
- PerlLIO_close(p[that]);
if (did_pipes)
PerlLIO_close(pp[1]);
/* Keep the lower of the two fd numbers */
@@ -2022,6 +2023,9 @@ Perl_my_popen_list(pTHX_ char *mode, int n, SV **args)
PerlLIO_close(p[This]);
p[This] = p[that];
}
+ else
+ PerlLIO_close(p[that]); /* close child's end of pipe */
+
LOCK_FDPID_MUTEX;
sv = *av_fetch(PL_fdpid,p[This],TRUE);
UNLOCK_FDPID_MUTEX;