apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@apache.org
Subject svn commit: r584569 - /apr/apr/trunk/threadproc/unix/proc.c
Date Sun, 14 Oct 2007 17:35:49 GMT
Author: wrowe
Date: Sun Oct 14 10:35:48 2007
New Revision: 584569

URL: http://svn.apache.org/viewvc?rev=584569&view=rev
Log:
apr_file_dup() varies from dup2 by not setting the child handle as
inherited.  Solve this by setting the duplicated handle to inherit.

once finished with the fork(), now that we don't waste pipe creation
resources on a single handle, watch out for closing the parent handle
inside the child.

in fact I believe that toggling parent_* handles apr_file_inherit_unset
way back in apr_procattr_io_set / apr_procattr_child_*_set would be
more efficient; comments?

Modified:
    apr/apr/trunk/threadproc/unix/proc.c

Modified: apr/apr/trunk/threadproc/unix/proc.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/threadproc/unix/proc.c?rev=584569&r1=584568&r2=584569&view=diff
==============================================================================
--- apr/apr/trunk/threadproc/unix/proc.c (original)
+++ apr/apr/trunk/threadproc/unix/proc.c Sun Oct 14 10:35:48 2007
@@ -92,13 +92,18 @@
 
     if (attr->child_in == NULL && attr->parent_in == NULL
            && child_in == NULL && parent_in == NULL)
-        rv = apr_file_pipe_create(&attr->child_in, &attr->parent_in, attr->pool);
+        rv = apr_file_pipe_create(&attr->child_in, &attr->parent_in,
+                                  attr->pool);
     
     if (child_in != NULL && rv == APR_SUCCESS) {
         if (attr->child_in && (attr->child_in->filedes != -1))
             rv = apr_file_dup2(attr->child_in, child_in, attr->pool);
-        else
-            rv = apr_file_dup(&attr->child_in, child_in, attr->pool);
+        else {
+            attr->child_in = NULL;
+            if ((rv = apr_file_dup(&attr->child_in, child_in, attr->pool))
+                    == APR_SUCCESS)
+                rv = apr_file_inherit_set(attr->child_in);
+        }
     }
 
     if (parent_in != NULL && rv == APR_SUCCESS) {
@@ -120,13 +125,18 @@
 
     if (attr->child_out == NULL && attr->parent_out == NULL
            && child_out == NULL && parent_out == NULL)
-        rv = apr_file_pipe_create(&attr->child_out, &attr->parent_out, attr->pool);
+        rv = apr_file_pipe_create(&attr->parent_out, &attr->child_out,
+                                  attr->pool);
 
     if (child_out != NULL && rv == APR_SUCCESS) {
         if (attr->child_out && (attr->child_out->filedes != -1))
             rv = apr_file_dup2(attr->child_out, child_out, attr->pool);
-        else
-            rv = apr_file_dup(&attr->child_out, child_out, attr->pool);
+        else {
+            attr->child_out = NULL;
+            if ((rv = apr_file_dup(&attr->child_out, child_out, attr->pool))
+                    == APR_SUCCESS)
+                rv = apr_file_inherit_set(attr->child_out);
+        }
     }
 
     if (parent_out != NULL && rv == APR_SUCCESS) {
@@ -148,13 +158,18 @@
 
     if (attr->child_err == NULL && attr->parent_err == NULL
            && child_err == NULL && parent_err == NULL)
-        rv = apr_file_pipe_create(&attr->child_err, &attr->parent_err, attr->pool);
+        rv = apr_file_pipe_create(&attr->parent_err, &attr->child_err,
+                                  attr->pool);
 
     if (child_err != NULL && rv == APR_SUCCESS) {
         if (attr->child_err && (attr->child_err->filedes != -1))
             rv = apr_file_dup2(attr->child_err, child_err, attr->pool);
-        else
-            rv = apr_file_dup(&attr->child_err, child_err, attr->pool);
+        else {
+            attr->child_err = NULL;
+            if ((rv = apr_file_dup(&attr->child_err, child_err, attr->pool))
+                    == APR_SUCCESS)
+                rv = apr_file_inherit_set(attr->child_err);
+        }
     }
     if (parent_err != NULL && rv == APR_SUCCESS) {
         if (attr->parent_err)
@@ -409,7 +424,8 @@
             close(STDIN_FILENO);
         }
         else if (attr->child_in) {
-            apr_file_close(attr->parent_in);
+            if (attr->parent_in)
+                apr_file_close(attr->parent_in);
             dup2(attr->child_in->filedes, STDIN_FILENO);
             apr_file_close(attr->child_in);
         }
@@ -418,7 +434,8 @@
             close(STDOUT_FILENO);
         }
         else if (attr->child_out) {
-            apr_file_close(attr->parent_out);
+            if (attr->parent_out)
+                apr_file_close(attr->parent_out);
             dup2(attr->child_out->filedes, STDOUT_FILENO);
             apr_file_close(attr->child_out);
         }
@@ -427,7 +444,8 @@
             close(STDERR_FILENO);
         }
         else if (attr->child_err) {
-            apr_file_close(attr->parent_err);
+            if (attr->parent_err)
+                apr_file_close(attr->parent_err);
             dup2(attr->child_err->filedes, STDERR_FILENO);
             apr_file_close(attr->child_err);
         }



Mime
View raw message