You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Jeff Trawick <tr...@attglobal.net> on 2001/10/23 22:15:55 UTC

[PATCH] fd issue with apr_proc_create() and cleanup for exec

scenario:

. create a child process and enable pipes for the standard descriptors
  (0-2)
. have registered cleanups for files which use any of the standard
  descriptors

problem:

  the dup2() calls in the child to set up the pipes on the standard
  descriptors close whatever was on those descriptors before

  cleanup for exec closes not what was on those descriptors before but
  instead closes the pipes

  child process gets EBADF when reading from stdin or writing to
  stdout/stderr

quick hack:

  tweak the order of processing in the child so that the cleanup
  happens before we set up our pipes on the standard descriptors

This patch is barely tested; it gets my silly apache module to work,
but I can't make any other promises.

Index: srclib/apr/threadproc/unix/proc.c
===================================================================
RCS file: /home/cvs/apr/threadproc/unix/proc.c,v
retrieving revision 1.50
diff -u -r1.50 proc.c
--- srclib/apr/threadproc/unix/proc.c	2001/10/23 17:30:08	1.50
+++ srclib/apr/threadproc/unix/proc.c	2001/10/23 20:00:40
@@ -289,6 +289,12 @@
     else if (new->pid == 0) { 
         int status;
         /* child process */
+
+        /* do exec cleanup before duping pipes to fds 0-2; otherwise,
+         * any files cleaned up with those fds will hose our pipes
+         */
+        apr_pool_cleanup_for_exec();
+
         if (attr->child_in) {
             apr_file_close(attr->parent_in);
             dup2(attr->child_in->filedes, STDIN_FILENO);
@@ -312,8 +318,6 @@
                 exit(-1);   /* We have big problems, the child should exit. */
             }
         }
-
-        apr_pool_cleanup_for_exec();
 
         if ((status = limit_proc(attr)) != APR_SUCCESS) {
             return status;

-- 
Jeff Trawick | trawick@attglobal.net | PGP public key at web site:
       http://www.geocities.com/SiliconValley/Park/9289/
             Born in Roswell... married an alien...