This is the mail archive of the libc-alpha@cygnus.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: popen/pclose problem in Linux 2.2.x with vfork/glibc 2.1



Thanks for all replies.  I do think we have to use fork instead of
vfork for popen in glibc since the code changes some globals and calls
dup2 and close:

  ((_IO_proc_file *) fp)->pid = child_pid = _IO_fork ();
  if (child_pid == 0)
    {
      int child_std_end = mode[0] == 'r' ? 1 : 0;
      _IO_close (parent_end);
      if (child_end != child_std_end)
	{
	  _IO_dup2 (child_end, child_std_end);
	  _IO_close (child_end);
	}
      /* POSIX.2:  "popen() shall ensure that any streams from previous
         popen() calls that remain open in the parent process are closed
	 in the new child process." */
      while (proc_file_chain)
	{
	  _IO_close (_IO_fileno ((_IO_FILE *) proc_file_chain));
	  proc_file_chain = proc_file_chain->next;
	}

      _IO_execl ("/bin/sh", "sh", "-c", command, (char *) 0);
      _IO__exit (127);

The appended patch fixes the reported bug.
Andreas

1999-03-28  Andreas Jaeger  <aj@arthur.rhein-neckar.de>

	* libio/iopopen.c (_IO_fork): Use fork instead of vfork since
	vfork doesn't allow e.g. closing dup2 and close calls.
        Fixes PR libc/966+967.

--- libio/iopopen.c.~1~	Mon Nov 23 19:58:12 1998
+++ libio/iopopen.c	Sun Mar 28 12:01:11 1999
@@ -1,4 +1,4 @@
-/* Copyright (C) 1993, 1997, 1998 Free Software Foundation, Inc.
+/* Copyright (C) 1993, 1997, 1998, 1999 Free Software Foundation, Inc.
    This file is part of the GNU IO Library.
    Written by Per Bothner <bothner@cygnus.com>.
 
@@ -42,9 +42,9 @@
 
 #ifndef _IO_fork
 #ifdef _LIBC
-#define _IO_fork __vfork
+#define _IO_fork __fork
 #else
-#define _IO_fork vfork /* defined in libiberty, if needed */
+#define _IO_fork fork /* defined in libiberty, if needed */
 #endif
 extern _IO_pid_t _IO_fork __P ((void));
 #endif


-- 
 Andreas Jaeger   aj@arthur.rhein-neckar.de    jaeger@informatik.uni-kl.de
  for pgp-key finger ajaeger@aixd1.rhrk.uni-kl.de


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]