aboutsummaryrefslogtreecommitdiff
path: root/libio/iopopen.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2007-07-19 17:02:07 +0000
committerUlrich Drepper <drepper@redhat.com>2007-07-19 17:02:07 +0000
commitd8d7feefa738eb3138790c99aa891ef44d85e4cc (patch)
treefd31284344efccd8bd724f12908c741fbd929f21 /libio/iopopen.c
parent2e2efe652a61fc081a0f08ecfe6c46fddead1fd0 (diff)
downloadglibc-d8d7feefa738eb3138790c99aa891ef44d85e4cc.zip
glibc-d8d7feefa738eb3138790c99aa891ef44d85e4cc.tar.gz
glibc-d8d7feefa738eb3138790c99aa891ef44d85e4cc.tar.bz2
(_IO_new_proc_open): Don't close child_std_end if one of proc_file_chain streams has that fileno.
Diffstat (limited to 'libio/iopopen.c')
-rw-r--r--libio/iopopen.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/libio/iopopen.c b/libio/iopopen.c
index 896e930..d5c6305 100644
--- a/libio/iopopen.c
+++ b/libio/iopopen.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 1993, 1997-2002, 2003, 2004 Free Software Foundation, Inc.
+/* Copyright (C) 1993, 1997-2002, 2003, 2004, 2007
+ Free Software Foundation, Inc.
This file is part of the GNU C Library.
Written by Per Bothner <bothner@cygnus.com>.
@@ -169,7 +170,15 @@ _IO_new_proc_open (fp, command, mode)
popen() calls that remain open in the parent process are closed
in the new child process." */
for (p = proc_file_chain; p; p = p->next)
- _IO_close (_IO_fileno ((_IO_FILE *) p));
+ {
+ int fd = _IO_fileno ((_IO_FILE *) p);
+
+ /* If any stream from previous popen() calls has fileno
+ child_std_end, it has been already closed by the dup2 syscall
+ above. */
+ if (fd != child_std_end)
+ _IO_close (fd);
+ }
_IO_execl ("/bin/sh", "sh", "-c", command, (char *) 0);
_IO__exit (127);