apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@apache.org
Subject svn commit: r584570 - /apr/apr/trunk/threadproc/unix/proc.c
Date Sun, 14 Oct 2007 18:00:39 GMT
Author: wrowe
Date: Sun Oct 14 11:00:37 2007
New Revision: 584570

URL: http://svn.apache.org/viewvc?rev=584570&view=rev
Log:
Here's my recommendation; upon opening the pipes, always set the parent-end
of the pipe to uninherited.  Let it be closed upon cleanup_for_exec.

The later dup2() for the parent pipe does not automagically become inherited
again, and later dup()'s are never inherited by default.

There's no longer an explicit need to close the parent-end in proc_create

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=584570&r1=584569&r2=584570&view=diff
==============================================================================
--- apr/apr/trunk/threadproc/unix/proc.c (original)
+++ apr/apr/trunk/threadproc/unix/proc.c Sun Oct 14 11:00:37 2007
@@ -58,7 +58,9 @@
             in = APR_WRITE_BLOCK;
 
         if ((rv = apr_file_pipe_create_ex(&attr->child_in, &attr->parent_in,
-                                          in, attr->pool)) != APR_SUCCESS)
+                                          in, attr->pool)) == APR_SUCCESS)
+            rv = apr_file_inherit_unset(attr->parent_in);
+        if (rv != APR_SUCCESS)
             return rv;
     }
     else if (in == APR_NO_FILE)
@@ -66,7 +68,9 @@
 
     if ((out != APR_NO_PIPE) && (out != APR_NO_FILE)) {
         if ((rv = apr_file_pipe_create_ex(&attr->parent_out, &attr->child_out,
-                                          out, attr->pool)) != APR_SUCCESS)
+                                          out, attr->pool)) == APR_SUCCESS)
+            rv = apr_file_inherit_unset(attr->parent_out);
+        if (rv != APR_SUCCESS)
             return rv;
     }
     else if (out == APR_NO_FILE)
@@ -75,6 +79,8 @@
     if ((err != APR_NO_PIPE) && (err != APR_NO_FILE)) {
         if ((rv = apr_file_pipe_create_ex(&attr->parent_err, &attr->child_err,
                                           err, attr->pool)) != APR_SUCCESS)
+            rv = apr_file_inherit_unset(attr->parent_err);
+        if (rv != APR_SUCCESS)
             return rv;
     }
     else if (err == APR_NO_FILE)
@@ -92,9 +98,10 @@
 
     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);
-    
+        if ((rv = apr_file_pipe_create(&attr->child_in, &attr->parent_in,
+                                       attr->pool)) == APR_SUCCESS)
+            rv = apr_file_inherit_unset(attr->parent_in);
+
     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);
@@ -125,8 +132,9 @@
 
     if (attr->child_out == NULL && attr->parent_out == NULL
            && child_out == NULL && parent_out == NULL)
-        rv = apr_file_pipe_create(&attr->parent_out, &attr->child_out,
-                                  attr->pool);
+        if ((rv = apr_file_pipe_create(&attr->parent_out, &attr->child_out,
+                                       attr->pool)) == APR_SUCCESS)
+            rv = apr_file_inherit_unset(attr->parent_out);
 
     if (child_out != NULL && rv == APR_SUCCESS) {
         if (attr->child_out && (attr->child_out->filedes != -1))
@@ -158,8 +166,9 @@
 
     if (attr->child_err == NULL && attr->parent_err == NULL
            && child_err == NULL && parent_err == NULL)
-        rv = apr_file_pipe_create(&attr->parent_err, &attr->child_err,
-                                  attr->pool);
+        if ((rv = apr_file_pipe_create(&attr->parent_err, &attr->child_err,
+                                      attr->pool)) == APR_SUCCESS)
+            rv = apr_file_inherit_unset(attr->parent_err);
 
     if (child_err != NULL && rv == APR_SUCCESS) {
         if (attr->child_err && (attr->child_err->filedes != -1))
@@ -424,8 +433,6 @@
             close(STDIN_FILENO);
         }
         else if (attr->child_in) {
-            if (attr->parent_in)
-                apr_file_close(attr->parent_in);
             dup2(attr->child_in->filedes, STDIN_FILENO);
             apr_file_close(attr->child_in);
         }
@@ -434,8 +441,6 @@
             close(STDOUT_FILENO);
         }
         else if (attr->child_out) {
-            if (attr->parent_out)
-                apr_file_close(attr->parent_out);
             dup2(attr->child_out->filedes, STDOUT_FILENO);
             apr_file_close(attr->child_out);
         }
@@ -444,8 +449,6 @@
             close(STDERR_FILENO);
         }
         else if (attr->child_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