From: Gurusamy Sarathy Date: Mon, 15 Jul 2002 23:58:49 +0000 (+0000) Subject: change#16528 merged the fix for my_popen() but missed my_popen_list() X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4e6dfe7129c097c1c55e03c2282efd9f7d35d6ff;p=p5sagit%2Fp5-mst-13.2.git 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 --- diff --git a/util.c b/util.c index 623c44c..e42efe3 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;