diff options
Diffstat (limited to 'threadproc/netware/proc.c')
-rw-r--r-- | threadproc/netware/proc.c | 223 |
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); |