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


   Date: Mon, 29 Mar 1999 12:56:26 -0500 (EST)
   From: Cristian Gafton <gafton@redhat.com>

   Add my "vote" for changing popen implementation to use fork instead of
   vfork.

It's possible that replacing vfork with fork doesn't fix the bug in
general, not to mention that it will hurt performance quite a bit for
some applications.

Solaris 7 libc popen uses vfork; this suggests that popen can be done
correctly with vfork.  Certainly portable programs should not assume
that popen uses fork.

I haven't been following this thread carefully so I don't know if this
has been mentioned before, but by code inspection here's an untested
patch for what seems to me to be a vfork-related bug in glibc 2.1.1
libio/iopopen.c.  The original code is executed in the child but it
affects the parent's proc_file_chain when vfork is used.

1999-03-29  Paul Eggert  <eggert@twinsun.com>

	* libio/iopopen.c (_IO_new_proc_open): Don't modify proc_file_chain
	while in child process.

--- glibc-2.1.1/iopopen.c	Mon Nov 23 07:22:46 1998
+++ glibc-fixed/iopopen.c	Mon Mar 29 13:38:06 1999
@@ -139,6 +139,8 @@
   if (child_pid == 0)
     {
       int child_std_end = mode[0] == 'r' ? 1 : 0;
+      struct _IO_proc_file *p;
+
       _IO_close (parent_end);
       if (child_end != child_std_end)
 	{
@@ -148,11 +150,8 @@
       /* 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;
-	}
+      for (p = proc_file_chain; p; p = p->next)
+	_IO_close (_IO_fileno ((_IO_FILE *) p));
 
       _IO_execl ("/bin/sh", "sh", "-c", command, (char *) 0);
       _IO__exit (127);


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