You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by wr...@apache.org on 2007/10/15 23:30:12 UTC

svn commit: r584928 - in /apr/apr/trunk/threadproc: beos/proc.c netware/proc.c os2/proc.c

Author: wrowe
Date: Mon Oct 15 14:30:06 2007
New Revision: 584928

URL: http://svn.apache.org/viewvc?rev=584928&view=rev
Log:
Backport the std handling improvements to Netware, OS2, BeOS.
These may need massaging and do need review by their respective
communities.

Note that someone from the OS2 community needs to ping me with
resolving the missing apr_arch_inherit.h mess; this should be
very easy to translate into 

   DosSetFHState(handle, OPEN_FLAGS_NOINHERIT);

bits, but to more thoroughly resolve the issue, we should take
it a step further and consider the NT implementation which
toggles inheritance on only for handles as they hit proc_create,
so that you don't have cross-process handle leakage into the
wrong processes.


Modified:
    apr/apr/trunk/threadproc/beos/proc.c
    apr/apr/trunk/threadproc/netware/proc.c
    apr/apr/trunk/threadproc/os2/proc.c

Modified: apr/apr/trunk/threadproc/beos/proc.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/threadproc/beos/proc.c?rev=584928&r1=584927&r2=584928&view=diff
==============================================================================
--- apr/apr/trunk/threadproc/beos/proc.c (original)
+++ apr/apr/trunk/threadproc/beos/proc.c Mon Oct 15 14:30:06 2007
@@ -17,6 +17,11 @@
 #include "apr_arch_threadproc.h"
 #include "apr_strings.h"
 
+/* Heavy on no'ops, here's what we want to pass if there is APR_NO_FILE
+ * requested for a specific child handle;
+ */
+static apr_file_t no_file = { NULL, -1, };
+
 struct send_pipe {
 	int in;
 	int out;
@@ -44,70 +49,53 @@
     return APR_SUCCESS;
 }
 
-APR_DECLARE(apr_status_t) apr_procattr_io_set(apr_procattr_t *attr, apr_int32_t in, 
-                                              apr_int32_t out, apr_int32_t err)
-{
-    apr_status_t status;
-    if (in != 0) {
-        if ((status = apr_file_pipe_create(&attr->child_in, &attr->parent_in, 
-                                   attr->pool)) != APR_SUCCESS) {
-            return status;
-        }
-        switch (in) {
-        case APR_FULL_BLOCK:
-            apr_file_pipe_timeout_set(attr->child_in, -1);
-            apr_file_pipe_timeout_set(attr->parent_in, -1);
-            break;
-        case APR_PARENT_BLOCK:
-            apr_file_pipe_timeout_set(attr->child_in, -1);
-            break;
-        case APR_CHILD_BLOCK:
-            apr_file_pipe_timeout_set(attr->parent_in, -1);
-            break;
-        default:
-            break;
-        }
-    } 
-    if (out) {
-        if ((status = apr_file_pipe_create(&attr->parent_out, &attr->child_out, 
-                                   attr->pool)) != APR_SUCCESS) {
-            return status;
-        }
-        switch (out) {
-        case APR_FULL_BLOCK:
-            apr_file_pipe_timeout_set(attr->child_out, -1);
-            apr_file_pipe_timeout_set(attr->parent_out, -1);       
-            break;
-        case APR_PARENT_BLOCK:
-            apr_file_pipe_timeout_set(attr->child_out, -1);
-            break;
-        case APR_CHILD_BLOCK:
-            apr_file_pipe_timeout_set(attr->parent_out, -1);
-            break;
-        default:
-            break;
-        }
-    } 
-    if (err) {
-        if ((status = apr_file_pipe_create(&attr->parent_err, &attr->child_err, 
-                                   attr->pool)) != APR_SUCCESS) {
-            return status;
-        }
-        switch (err) {
-        case APR_FULL_BLOCK:
-            apr_file_pipe_timeout_set(attr->child_err, -1);
-            apr_file_pipe_timeout_set(attr->parent_err, -1);
-            break;
-        case APR_PARENT_BLOCK:
-            apr_file_pipe_timeout_set(attr->child_err, -1);
-            break;
-        case APR_CHILD_BLOCK:
-            apr_file_pipe_timeout_set(attr->parent_err, -1);
-            break;
-        default:
-            break;
-        }
-    } 
+APR_DECLARE(apr_status_t) apr_procattr_io_set(apr_procattr_t *attr,
+                                              apr_int32_t in,
+                                              apr_int32_t out,
+                                              apr_int32_t err)
+{
+    apr_status_t rv;
+
+    if ((in != APR_NO_PIPE) && (in != APR_NO_FILE)) {
+        /* APR_CHILD_BLOCK maps to APR_WRITE_BLOCK, while
+         * APR_PARENT_BLOCK maps to APR_READ_BLOCK, so transpose 
+         * the CHILD/PARENT blocking flags for the stdin pipe.
+         * stdout/stderr map to the correct mode by default.
+         */
+        if (in == APR_CHILD_BLOCK)
+            in = APR_READ_BLOCK;
+        else if (in == APR_PARENT_BLOCK)
+            in = APR_WRITE_BLOCK;
+
+        if ((rv = apr_file_pipe_create_ex(&attr->child_in, &attr->parent_in,
+                                          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)
+        attr->child_in = &no_file;
+
+    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)
+            rv = apr_file_inherit_unset(attr->parent_out);
+        if (rv != APR_SUCCESS)
+            return rv;
+    }
+    else if (out == APR_NO_FILE)
+        attr->child_out = &no_file;
+
+    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)
+        attr->child_err = &no_file;
+
     return APR_SUCCESS;
 }
 
@@ -233,9 +221,9 @@
     new->in = attr->parent_in;
     new->err = attr->parent_err;
     new->out = attr->parent_out;
-	sp->in  = attr->child_in  ? attr->child_in->filedes  : -1;
-	sp->out = attr->child_out ? attr->child_out->filedes : -1;
-	sp->err = attr->child_err ? attr->child_err->filedes : -1;
+    sp->in  = attr->child_in  ? attr->child_in->filedes  : FILENO_STDIN;
+    sp->out = attr->child_out ? attr->child_out->filedes : FILENO_STDOUT;
+    sp->err = attr->child_err ? attr->child_err->filedes : FILENO_STDERR;
 
     i = 0;
     while (args && args[i]) {
@@ -277,13 +265,13 @@
 
     resume_thread(newproc);
 
-    if (attr->child_in) {
+    if (attr->child_in && (attr->child_in->filedes != -1)) {
         apr_file_close(attr->child_in);
     }
-    if (attr->child_out) {
+    if (attr->child_out && (attr->child_in->filedes != -1)) {
         apr_file_close(attr->child_out);
     }
-    if (attr->child_err) {
+    if (attr->child_err && (attr->child_in->filedes != -1)) {
         apr_file_close(attr->child_err);
     }
 
@@ -357,46 +345,84 @@
 APR_DECLARE(apr_status_t) apr_procattr_child_in_set(apr_procattr_t *attr, apr_file_t *child_in,
                                    apr_file_t *parent_in)
 {
-    if (attr->child_in == NULL && attr->parent_in == NULL)
-        apr_file_pipe_create(&attr->child_in, &attr->parent_in, attr->pool);
+    apr_status_t rv;
 
-    if (child_in != NULL)
-        apr_file_dup(&attr->child_in, child_in, attr->pool);
+    if (attr->child_in == NULL && attr->parent_in == NULL
+            && child_in == NULL && parent_in == NULL)
+        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);
+        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)
-        apr_file_dup(&attr->parent_in, parent_in, attr->pool);
+    if (parent_in != NULL && rv == APR_SUCCESS) {
+        rv = apr_file_dup(&attr->parent_in, parent_in, attr->pool);
 
-    return APR_SUCCESS;
+    return rv;
 }
 
 APR_DECLARE(apr_status_t) apr_procattr_child_out_set(apr_procattr_t *attr, apr_file_t *child_out,
                                                      apr_file_t *parent_out)
 {
-    if (attr->child_out == NULL && attr->parent_out == NULL)
-        apr_file_pipe_create(&attr->child_out, &attr->parent_out, attr->pool);
-
-    if (child_out != NULL)
-        apr_file_dup(&attr->child_out, child_out, attr->pool);
+    apr_status_t rv;
 
-    if (parent_out != NULL)
-        apr_file_dup(&attr->parent_out, parent_out, attr->pool);
+    if (attr->child_out == NULL && attr->parent_out == NULL
+           && child_out == NULL && parent_out == NULL)
+        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))
+            rv = apr_file_dup2(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) {
+        rv = apr_file_dup(&attr->parent_out, parent_out, attr->pool);
 
-    return APR_SUCCESS;
+    return rv;
 }
 
 APR_DECLARE(apr_status_t) apr_procattr_child_err_set(apr_procattr_t *attr, apr_file_t *child_err,
                                                      apr_file_t *parent_err)
 {
-    if (attr->child_err == NULL && attr->parent_err == NULL)
-        apr_file_pipe_create(&attr->child_err, &attr->parent_err, attr->pool);
+    apr_status_t rv;
 
-    if (child_err != NULL)
-        apr_file_dup(&attr->child_err, child_err, attr->pool);
-
-    if (parent_err != NULL)
-        apr_file_dup(&attr->parent_err, parent_err, attr->pool);
+    if (attr->child_err == NULL && attr->parent_err == NULL
+           && child_err == NULL && parent_err == NULL)
+        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))
+            rv = apr_file_dup2(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) {
+        rv = apr_file_dup(&attr->parent_err, parent_err, attr->pool);
 
-    return APR_SUCCESS;
+    return rv;
 }
 
 APR_DECLARE(apr_status_t) apr_procattr_limit_set(apr_procattr_t *attr, apr_int32_t what, 

Modified: apr/apr/trunk/threadproc/netware/proc.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/threadproc/netware/proc.c?rev=584928&r1=584927&r2=584928&view=diff
==============================================================================
--- apr/apr/trunk/threadproc/netware/proc.c (original)
+++ apr/apr/trunk/threadproc/netware/proc.c Mon Oct 15 14:30:06 2007
@@ -21,6 +21,11 @@
 
 #include <proc.h>
 
+/* Heavy on no'ops, here's what we want to pass if there is APR_NO_FILE
+ * requested for a specific child handle;
+ */
+static apr_file_t no_file = { NULL, -1, };
+
 apr_status_t apr_netware_proc_cleanup(void *theproc)
 {
     apr_proc_t *proc = theproc;
@@ -51,67 +56,53 @@
 
 }
 
-APR_DECLARE(apr_status_t) apr_procattr_io_set(apr_procattr_t *attr, apr_int32_t in, 
-                                 apr_int32_t out, apr_int32_t err)
-{
-    apr_status_t status;
-    if (in != 0) {
-        if ((status = apr_file_pipe_create(&attr->child_in, &attr->parent_in, 
-                                   attr->pool)) != APR_SUCCESS) {
-            return status;
-        }
-        switch (in) {
-        case APR_FULL_BLOCK:
-            break;
-        case APR_PARENT_BLOCK:
-            apr_file_pipe_timeout_set(attr->child_in, 0);
-            break;
-        case APR_CHILD_BLOCK:
-            apr_file_pipe_timeout_set(attr->parent_in, 0);
-            break;
-        default:
-            apr_file_pipe_timeout_set(attr->child_in, 0);
-            apr_file_pipe_timeout_set(attr->parent_in, 0);
-        }
-    } 
-    if (out) {
-        if ((status = apr_file_pipe_create(&attr->parent_out, &attr->child_out, 
-                                   attr->pool)) != APR_SUCCESS) {
-            return status;
-        }
-        switch (out) {
-        case APR_FULL_BLOCK:
-            break;
-        case APR_PARENT_BLOCK:
-            apr_file_pipe_timeout_set(attr->child_out, 0);
-            break;
-        case APR_CHILD_BLOCK:
-            apr_file_pipe_timeout_set(attr->parent_out, 0);
-            break;
-        default:
-            apr_file_pipe_timeout_set(attr->child_out, 0);
-            apr_file_pipe_timeout_set(attr->parent_out, 0);
-        }
-    } 
-    if (err) {
-        if ((status = apr_file_pipe_create(&attr->parent_err, &attr->child_err, 
-                                   attr->pool)) != APR_SUCCESS) {
-            return status;
-        }
-        switch (err) {
-        case APR_FULL_BLOCK:
-            break;
-        case APR_PARENT_BLOCK:
-            apr_file_pipe_timeout_set(attr->child_err, 0);
-            break;
-        case APR_CHILD_BLOCK:
-            apr_file_pipe_timeout_set(attr->parent_err, 0);
-            break;
-        default:
-            apr_file_pipe_timeout_set(attr->child_err, 0);
-            apr_file_pipe_timeout_set(attr->parent_err, 0);
-        }
-    } 
+APR_DECLARE(apr_status_t) apr_procattr_io_set(apr_procattr_t *attr,
+                                              apr_int32_t in,
+                                              apr_int32_t out,
+                                              apr_int32_t err)
+{
+    apr_status_t rv;
+
+    if ((in != APR_NO_PIPE) && (in != APR_NO_FILE)) {
+        /* APR_CHILD_BLOCK maps to APR_WRITE_BLOCK, while
+         * APR_PARENT_BLOCK maps to APR_READ_BLOCK, so transpose 
+         * the CHILD/PARENT blocking flags for the stdin pipe.
+         * stdout/stderr map to the correct mode by default.
+         */
+        if (in == APR_CHILD_BLOCK)
+            in = APR_READ_BLOCK;
+        else if (in == APR_PARENT_BLOCK)
+            in = APR_WRITE_BLOCK;
+
+        if ((rv = apr_file_pipe_create_ex(&attr->child_in, &attr->parent_in,
+                                          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)
+        attr->child_in = &no_file;
+
+    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)
+            rv = apr_file_inherit_unset(attr->parent_out);
+        if (rv != APR_SUCCESS)
+            return rv;
+    }
+    else if (out == APR_NO_FILE)
+        attr->child_out = &no_file;
+
+    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)
+        attr->child_err = &no_file;
+
     return APR_SUCCESS;
 }
 
@@ -119,48 +110,86 @@
 APR_DECLARE(apr_status_t) apr_procattr_child_in_set(apr_procattr_t *attr, apr_file_t *child_in,
                                    apr_file_t *parent_in)
 {
-    if (attr->child_in == NULL && attr->parent_in == NULL)
-        apr_file_pipe_create(&attr->child_in, &attr->parent_in, attr->pool);
+    apr_status_t rv;
 
-    if (child_in != NULL)
-        apr_file_dup2(attr->child_in, child_in, attr->pool);
+    if (attr->child_in == NULL && attr->parent_in == NULL
+            && child_in == NULL && parent_in == NULL)
+        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);
+        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)
-        apr_file_dup2(attr->parent_in, parent_in, attr->pool);
+    if (parent_in != NULL && rv == APR_SUCCESS) {
+        rv = apr_file_dup(&attr->parent_in, parent_in, attr->pool);
 
-    return APR_SUCCESS;
+    return rv;
 }
 
 
 APR_DECLARE(apr_status_t) apr_procattr_child_out_set(apr_procattr_t *attr, apr_file_t *child_out,
-                                    apr_file_t *parent_out)
+                                                     apr_file_t *parent_out)
 {
-    if (attr->child_out == NULL && attr->parent_out == NULL)
-        apr_file_pipe_create(&attr->child_out, &attr->parent_out, attr->pool);
-
-    if (child_out != NULL)
-        apr_file_dup2(attr->child_out, child_out, attr->pool);
+    apr_status_t rv;
 
-    if (parent_out != NULL)
-        apr_file_dup2(attr->parent_out, parent_out, attr->pool);
+    if (attr->child_out == NULL && attr->parent_out == NULL
+           && child_out == NULL && parent_out == NULL)
+        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))
+            rv = apr_file_dup2(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) {
+        rv = apr_file_dup(&attr->parent_out, parent_out, attr->pool);
 
-    return APR_SUCCESS;
+    return rv;
 }
 
 
 APR_DECLARE(apr_status_t) apr_procattr_child_err_set(apr_procattr_t *attr, apr_file_t *child_err,
-                                   apr_file_t *parent_err)
+                                                     apr_file_t *parent_err)
 {
-    if (attr->child_err == NULL && attr->parent_err == NULL)
-        apr_file_pipe_create(&attr->child_err, &attr->parent_err, attr->pool);
+    apr_status_t rv;
 
-    if (child_err != NULL)
-        apr_file_dup2(attr->child_err, child_err, attr->pool);
+    if (attr->child_err == NULL && attr->parent_err == NULL
+           && child_err == NULL && parent_err == NULL)
+        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))
+            rv = apr_file_dup2(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) {
+        rv = apr_file_dup(&attr->parent_err, parent_err, attr->pool);
 
-    if (parent_err != NULL)
-        apr_file_dup2(attr->parent_err, parent_err, attr->pool);
-
-    return APR_SUCCESS;
+    return rv;
 }
 
 
@@ -280,12 +309,21 @@
                               		apr_procattr_t *attr, 
                               		apr_pool_t *pool)
 {
-	wiring_t		wire;
-    int             addr_space;
+    wiring_t wire;
+    int      addr_space;
 
-    wire.infd  = attr->child_in ? attr->child_in->filedes : FD_UNUSED;
-    wire.outfd = attr->child_out ? attr->child_out->filedes : FD_UNUSED;
-    wire.errfd = attr->child_err ? attr->child_err->filedes : FD_UNUSED;
+    wire.infd  = attr->child_in  
+               ? (attr->child_in->filedes != -1 ? attr->child_in->filedes 
+                                                : FD_UNUSED)
+               : FILENO_STDIN;
+    wire.outfd  = attr->child_out
+                ? (attr->child_out->filedes != -1 ? attr->child_out->filedes 
+                                                  : FD_UNUSED)
+                : FILENO_STDOUT;
+    wire.errfd  = attr->child_err
+                ? (attr->child_err->filedes != -1 ? attr->child_err->filedes 
+                                                  : FD_UNUSED)
+                : FILENO_STDERR;
 
     newproc->in = attr->parent_in;
     newproc->out = attr->parent_out;
@@ -313,22 +351,21 @@
         return errno;
     }
 
-    if (attr->child_in) {
+    if (attr->child_in && (attr->child_in->filedes != -1)) {
         apr_pool_cleanup_kill(apr_file_pool_get(attr->child_in), 
                               attr->child_in, apr_unix_file_cleanup);
         apr_file_close(attr->child_in);
     }
-    if (attr->child_out) {
+    if (attr->child_out && (attr->child_out->filedes != -1)) {
         apr_pool_cleanup_kill(apr_file_pool_get(attr->child_out), 
                               attr->child_out, apr_unix_file_cleanup);
         apr_file_close(attr->child_out);
     }
-    if (attr->child_err) {
+    if (attr->child_err && (attr->child_err->filedes != -1)) {
         apr_pool_cleanup_kill(apr_file_pool_get(attr->child_err), 
                               attr->child_err, apr_unix_file_cleanup);
         apr_file_close(attr->child_err);
     }
-
 
     apr_pool_cleanup_register(pool, (void *)newproc, apr_netware_proc_cleanup,
         apr_pool_cleanup_null);

Modified: apr/apr/trunk/threadproc/os2/proc.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/threadproc/os2/proc.c?rev=584928&r1=584927&r2=584928&view=diff
==============================================================================
--- apr/apr/trunk/threadproc/os2/proc.c (original)
+++ apr/apr/trunk/threadproc/os2/proc.c Mon Oct 15 14:30:06 2007
@@ -34,6 +34,11 @@
 #include <process.h>
 #include <stdlib.h>
 
+/* Heavy on no'ops, here's what we want to pass if there is APR_NO_FILE
+ * requested for a specific child handle;
+ */
+static apr_file_t no_file = { NULL, -1, };
+
 APR_DECLARE(apr_status_t) apr_procattr_create(apr_procattr_t **new, apr_pool_t *pool)
 {
     (*new) = (apr_procattr_t *)apr_palloc(pool, 
@@ -55,118 +60,139 @@
     return APR_SUCCESS;
 }
 
-APR_DECLARE(apr_status_t) apr_procattr_io_set(apr_procattr_t *attr, apr_int32_t in, 
-                                              apr_int32_t out, apr_int32_t err)
-{
-    apr_status_t stat;
-    if (in) {
-        if ((stat = apr_file_pipe_create(&attr->child_in, &attr->parent_in,
-                                   attr->pool)) != APR_SUCCESS) {
-            return stat;
-        }
-        switch (in) {
-        case APR_FULL_BLOCK:
-            break;
-        case APR_PARENT_BLOCK:
-            apr_file_pipe_timeout_set(attr->child_in, 0);
-            break;
-        case APR_CHILD_BLOCK:
-            apr_file_pipe_timeout_set(attr->parent_in, 0);
-            break;
-        default:
-            apr_file_pipe_timeout_set(attr->child_in, 0);
-            apr_file_pipe_timeout_set(attr->parent_in, 0);
-        }
-    } 
-    if (out) {
-        if ((stat = apr_file_pipe_create(&attr->parent_out, &attr->child_out,
-                                   attr->pool)) != APR_SUCCESS) {
-            return stat;
-        }
-        switch (out) {
-        case APR_FULL_BLOCK:
-            break;
-        case APR_PARENT_BLOCK:
-            apr_file_pipe_timeout_set(attr->child_out, 0);
-            break;
-        case APR_CHILD_BLOCK:
-            apr_file_pipe_timeout_set(attr->parent_out, 0);
-            break;
-        default:
-            apr_file_pipe_timeout_set(attr->child_out, 0);
-            apr_file_pipe_timeout_set(attr->parent_out, 0);
-        }
-    } 
-    if (err) {
-        if ((stat = apr_file_pipe_create(&attr->parent_err, &attr->child_err,
-                                   attr->pool)) != APR_SUCCESS) {
-            return stat;
-        }
-        switch (err) {
-        case APR_FULL_BLOCK:
-            break;
-        case APR_PARENT_BLOCK:
-            apr_file_pipe_timeout_set(attr->child_err, 0);
-            break;
-        case APR_CHILD_BLOCK:
-            apr_file_pipe_timeout_set(attr->parent_err, 0);
-            break;
-        default:
-            apr_file_pipe_timeout_set(attr->child_err, 0);
-            apr_file_pipe_timeout_set(attr->parent_err, 0);
-        }
-    } 
+APR_DECLARE(apr_status_t) apr_procattr_io_set(apr_procattr_t *attr,
+                                              apr_int32_t in,
+                                              apr_int32_t out,
+                                              apr_int32_t err)
+{
+    apr_status_t rv;
+
+    if ((in != APR_NO_PIPE) && (in != APR_NO_FILE)) {
+        /* APR_CHILD_BLOCK maps to APR_WRITE_BLOCK, while
+         * APR_PARENT_BLOCK maps to APR_READ_BLOCK, so transpose 
+         * the CHILD/PARENT blocking flags for the stdin pipe.
+         * stdout/stderr map to the correct mode by default.
+         */
+        if (in == APR_CHILD_BLOCK)
+            in = APR_READ_BLOCK;
+        else if (in == APR_PARENT_BLOCK)
+            in = APR_WRITE_BLOCK;
+
+        if ((rv = apr_file_pipe_create_ex(&attr->child_in, &attr->parent_in,
+                                          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)
+        attr->child_in = &no_file;
+
+    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)
+            rv = apr_file_inherit_unset(attr->parent_out);
+        if (rv != APR_SUCCESS)
+            return rv;
+    }
+    else if (out == APR_NO_FILE)
+        attr->child_out = &no_file;
+
+    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)
+        attr->child_err = &no_file;
+
     return APR_SUCCESS;
 }
 
 APR_DECLARE(apr_status_t) apr_procattr_child_in_set(apr_procattr_t *attr, apr_file_t *child_in,
-                                                    apr_file_t *parent_in)
+                                   apr_file_t *parent_in)
 {
-    if (attr->child_in == NULL && attr->parent_in == NULL)
-        apr_file_pipe_create(&attr->child_in, &attr->parent_in, attr->pool);
+    apr_status_t rv;
 
-    if (child_in != NULL)
-        apr_file_dup(&attr->child_in, child_in, attr->pool);
+    if (attr->child_in == NULL && attr->parent_in == NULL
+            && child_in == NULL && parent_in == NULL)
+        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);
+        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)
-        apr_file_dup(&attr->parent_in, parent_in, attr->pool);
+    if (parent_in != NULL && rv == APR_SUCCESS) {
+        rv = apr_file_dup(&attr->parent_in, parent_in, attr->pool);
 
-    return APR_SUCCESS;
+    return rv;
 }
 
-
 APR_DECLARE(apr_status_t) apr_procattr_child_out_set(apr_procattr_t *attr, apr_file_t *child_out,
                                                      apr_file_t *parent_out)
 {
-    if (attr->child_out == NULL && attr->parent_out == NULL)
-        apr_file_pipe_create(&attr->child_out, &attr->parent_out, attr->pool);
+    apr_status_t rv;
 
-    if (child_out != NULL)
-        apr_file_dup(&attr->child_out, child_out, attr->pool);
-
-    if (parent_out != NULL)
-        apr_file_dup(&attr->parent_out, parent_out, attr->pool);
+    if (attr->child_out == NULL && attr->parent_out == NULL
+           && child_out == NULL && parent_out == NULL)
+        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))
+            rv = apr_file_dup2(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) {
+        rv = apr_file_dup(&attr->parent_out, parent_out, attr->pool);
 
-    return APR_SUCCESS;
+    return rv;
 }
 
-
 APR_DECLARE(apr_status_t) apr_procattr_child_err_set(apr_procattr_t *attr, apr_file_t *child_err,
                                                      apr_file_t *parent_err)
 {
-    if (attr->child_err == NULL && attr->parent_err == NULL)
-        apr_file_pipe_create(&attr->child_err, &attr->parent_err, attr->pool);
-
-    if (child_err != NULL)
-        apr_file_dup(&attr->child_err, child_err, attr->pool);
+    apr_status_t rv;
 
-    if (parent_err != NULL)
-        apr_file_dup(&attr->parent_err, parent_err, attr->pool);
+    if (attr->child_err == NULL && attr->parent_err == NULL
+           && child_err == NULL && parent_err == NULL)
+        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))
+            rv = apr_file_dup2(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) {
+        rv = apr_file_dup(&attr->parent_err, parent_err, attr->pool);
 
-    return APR_SUCCESS;
+    return rv;
 }
 
-
 APR_DECLARE(apr_status_t) apr_procattr_dir_set(apr_procattr_t *attr, const char *dir)
 {
     attr->currdir = apr_pstrdup(attr->pool, dir);
@@ -284,6 +310,10 @@
     char *env_block, *env_block_pos;
     RESULTCODES rescodes;
 
+    proc->in = attr->parent_in;
+    proc->err = attr->parent_err;
+    proc->out = attr->parent_out;
+
     /* Prevent other threads from running while these process-wide resources are modified */
     if (attr->child_in || attr->child_out || attr->child_err || attr->currdir) {
         criticalsection = TRUE;
@@ -294,24 +324,30 @@
         save_in = -1;
         DosDupHandle(STDIN_FILENO, &save_in);
         dup = STDIN_FILENO;
-        DosDupHandle(attr->child_in->filedes, &dup);
-        DosSetFHState(attr->parent_in->filedes, OPEN_FLAGS_NOINHERIT);
+        if (attr->child_in->filedes == -1)
+            DosClose(dup);
+        else
+            DosDupHandle(attr->child_in->filedes, &dup);
     }
     
     if (attr->child_out) {
         save_out = -1;
         DosDupHandle(STDOUT_FILENO, &save_out);
         dup = STDOUT_FILENO;
-        DosDupHandle(attr->child_out->filedes, &dup);
-        DosSetFHState(attr->parent_out->filedes, OPEN_FLAGS_NOINHERIT);
+        if (attr->child_out->filedes == -1)
+            DosClose(dup);
+        else
+            DosDupHandle(attr->child_out->filedes, &dup);
     }
     
     if (attr->child_err) {
         save_err = -1;
         DosDupHandle(STDERR_FILENO, &save_err);
         dup = STDERR_FILENO;
-        DosDupHandle(attr->child_err->filedes, &dup);
-        DosSetFHState(attr->parent_err->filedes, OPEN_FLAGS_NOINHERIT);
+        if (attr->child_err->filedes == -1)
+            DosClose(dup);
+        else
+            DosDupHandle(attr->child_err->filedes, &dup);
     }
 
     apr_signal(SIGCHLD, SIG_DFL); /*not sure if this is needed or not */
@@ -464,21 +500,24 @@
     }
 
     if (attr->child_in) {
-        apr_file_close(attr->child_in);
+        (attr->child_in->filedes != -1)
+            apr_file_close(attr->child_in);
         dup = STDIN_FILENO;
         DosDupHandle(save_in, &dup);
         DosClose(save_in);
     }
     
     if (attr->child_out) {
-        apr_file_close(attr->child_out);
+        (attr->child_err->filedes != -1)
+            apr_file_close(attr->child_out);
         dup = STDOUT_FILENO;
         DosDupHandle(save_out, &dup);
         DosClose(save_out);
     }
     
     if (attr->child_err) {
-        apr_file_close(attr->child_err);
+        (attr->child_err->filedes != -1)
+            apr_file_close(attr->child_err);
         dup = STDERR_FILENO;
         DosDupHandle(save_err, &dup);
         DosClose(save_err);
@@ -487,9 +526,6 @@
     if (criticalsection)
         DosExitCritSec();
 
-    proc->in = attr->parent_in;
-    proc->err = attr->parent_err;
-    proc->out = attr->parent_out;
     return status;
 }