summaryrefslogtreecommitdiff
path: root/threadproc/netware
diff options
context:
space:
mode:
authorWilliam A. Rowe Jr <wrowe@apache.org>2007-10-15 21:30:06 +0000
committerWilliam A. Rowe Jr <wrowe@apache.org>2007-10-15 21:30:06 +0000
commit3e695c3ccc465a00df30bcff488fa9e7b061f1b3 (patch)
tree6b1dfb5148af95fbd01884639f806b70399c95e9 /threadproc/netware
parent6e87b5e779b21474e895cbb13180be96e54de9f7 (diff)
downloadapr-3e695c3ccc465a00df30bcff488fa9e7b061f1b3.tar.gz
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. git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@584928 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'threadproc/netware')
-rw-r--r--threadproc/netware/proc.c223
1 files changed, 130 insertions, 93 deletions
diff --git a/threadproc/netware/proc.c b/threadproc/netware/proc.c
index 0f7077699..bed7d2a2a 100644
--- a/threadproc/netware/proc.c
+++ b/threadproc/netware/proc.c
@@ -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_create(apr_procattr_t **new,apr_pool_t *p
}
-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_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_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_io_set(apr_procattr_t *attr, apr_int32_t
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 (parent_in != NULL)
- apr_file_dup2(attr->parent_in, 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 {
+ 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);
+ }
- return APR_SUCCESS;
+ if (parent_in != NULL && rv == APR_SUCCESS) {
+ rv = apr_file_dup(&attr->parent_in, parent_in, attr->pool);
+
+ 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);
+ apr_status_t rv;
- if (child_out != NULL)
- apr_file_dup2(attr->child_out, child_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 (parent_out != NULL)
- apr_file_dup2(attr->parent_out, parent_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 {
+ 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 (parent_err != NULL)
- apr_file_dup2(attr->parent_err, parent_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 {
+ 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;
}
@@ -280,12 +309,21 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *newproc,
apr_procattr_t *attr,
apr_pool_t *pool)
{
- 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;
+ wiring_t wire;
+ int addr_space;
+
+ 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,23 +351,22 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *newproc,
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);