apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Trawick <traw...@attglobal.net>
Subject [PATCH] fix some apr_proc_create() file descriptor bungling, take 2 :)
Date Sat, 27 Oct 2001 02:46:43 GMT
Hopefully the comment I added in the last commit in combination with
the simple code change below will be understandable and perhaps even
correct.

It works for me with both mod_cgid and another module which gets
apr_proc_create() to do more of the pipe setup.

Index: srclib/apr/threadproc/unix/proc.c
===================================================================
RCS file: /home/cvspublic/apr/threadproc/unix/proc.c,v
retrieving revision 1.52
diff -u -r1.52 proc.c
--- srclib/apr/threadproc/unix/proc.c	2001/10/27 00:48:19	1.52
+++ srclib/apr/threadproc/unix/proc.c	2001/10/27 02:32:02
@@ -290,8 +290,7 @@
         int status;
         /* child process */
 
-        /* XXX major SNAFU
-         *
+        /*
          * If we do exec cleanup before the dup2() calls to set up pipes 
          * on 0-2, we accidentally close the pipes used by programs like 
          * mod_cgid.
@@ -299,9 +298,27 @@
          * If we do exec cleanup after the dup2() calls, cleanup can accidentally
          * close our pipes which replaced any files which previously had
          * descriptors 0-2.
+         *
+         * The solution is to kill the cleanup for the pipes, then do
+         * exec cleanup, then do the dup2() calls.
          */
 
         if (attr->child_in) {
+            apr_pool_cleanup_kill(apr_file_pool_get(attr->child_in), 
+                                  attr->child_in, apr_unix_file_cleanup);
+        }
+        if (attr->child_out) {
+            apr_pool_cleanup_kill(apr_file_pool_get(attr->child_out),
+                                  attr->child_out, apr_unix_file_cleanup);
+        }
+        if (attr->child_err) {
+            apr_pool_cleanup_kill(apr_file_pool_get(attr->child_err),
+                                  attr->child_err, apr_unix_file_cleanup);
+        }
+
+        apr_pool_cleanup_for_exec();
+
+        if (attr->child_in) {
             apr_file_close(attr->parent_in);
             dup2(attr->child_in->filedes, STDIN_FILENO);
             apr_file_close(attr->child_in);
@@ -324,8 +341,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...

Mime
View raw message