(_IO_new_proc_open): Don't close child_std_end if one of proc_file_chain streams has that fileno.

This commit is contained in:
Ulrich Drepper 2007-07-19 17:02:07 +00:00
parent 2e2efe652a
commit d8d7feefa7
1 changed files with 11 additions and 2 deletions

View File

@ -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. This file is part of the GNU C Library.
Written by Per Bothner <bothner@cygnus.com>. 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 popen() calls that remain open in the parent process are closed
in the new child process." */ in the new child process." */
for (p = proc_file_chain; p; p = p->next) 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_execl ("/bin/sh", "sh", "-c", command, (char *) 0);
_IO__exit (127); _IO__exit (127);