aboutsummaryrefslogtreecommitdiff
path: root/threadproc/unix/proc.c
diff options
context:
space:
mode:
authorWilliam A. Rowe Jr <wrowe@apache.org>2007-10-14 17:35:48 +0000
committerWilliam A. Rowe Jr <wrowe@apache.org>2007-10-14 17:35:48 +0000
commitb091288305d27109a65c74bd012807c6ff673915 (patch)
tree30af7f5375b9d30f725c1eeb4bf1b2e8ebc246e0 /threadproc/unix/proc.c
parentea49238865fdef5580b6c411bc1c90b607a3abaa (diff)
downloadapr-b091288305d27109a65c74bd012807c6ff673915.tar.gz
apr-b091288305d27109a65c74bd012807c6ff673915.zip
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? git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@584569 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'threadproc/unix/proc.c')
-rw-r--r--threadproc/unix/proc.c42
1 files changed, 30 insertions, 12 deletions
diff --git a/threadproc/unix/proc.c b/threadproc/unix/proc.c
index 7ade722fa..8be773a1e 100644
--- a/threadproc/unix/proc.c
+++ b/threadproc/unix/proc.c
@@ -92,13 +92,18 @@ APR_DECLARE(apr_status_t) apr_procattr_child_in_set(apr_procattr_t *attr,
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 @@ APR_DECLARE(apr_status_t) apr_procattr_child_out_set(apr_procattr_t *attr,
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 @@ APR_DECLARE(apr_status_t) apr_procattr_child_err_set(apr_procattr_t *attr,
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 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
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 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
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 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new,
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);
}