summaryrefslogtreecommitdiff
path: root/threadproc
diff options
context:
space:
mode:
authorjerenkrantz <jerenkrantz@13f79535-47bb-0310-9956-ffa450edef68>2001-09-21 16:14:50 +0000
committerjerenkrantz <jerenkrantz@13f79535-47bb-0310-9956-ffa450edef68>2001-09-21 16:14:50 +0000
commit82ecc2eed66f2fc86a2ca40891a1519b2509dd63 (patch)
treeefd2254a42962c5174d752671a114fb90f892380 /threadproc
parent84136a20dc774c31875d3062f7e46a7487bf1a4c (diff)
downloadlibapr-82ecc2eed66f2fc86a2ca40891a1519b2509dd63.tar.gz
Simplify apr_proc_wait_all_procs and consolidate apr_proc_wait.
(I had a similar version in my tree. Kevin's wins out because of the WIF macros. Are there any platforms that don't have this? The Solaris man page seems to indicate that they must be called, so it seems correct. Please check on your favorite platform.) Submitted by: Kevin Pilch-Bisson <kevin@pilch-bisson.net> Reviewed by: Justin Erenkrantz git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@62358 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'threadproc')
-rw-r--r--threadproc/unix/proc.c45
1 files changed, 21 insertions, 24 deletions
diff --git a/threadproc/unix/proc.c b/threadproc/unix/proc.c
index 619b18d89..894f36ea3 100644
--- a/threadproc/unix/proc.c
+++ b/threadproc/unix/proc.c
@@ -361,22 +361,13 @@ APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new, const char *progname,
return APR_SUCCESS;
}
-APR_DECLARE(apr_status_t) apr_proc_wait_all_procs(apr_proc_t *proc, apr_wait_t *status,
- apr_wait_how_e waithow, apr_pool_t *p)
+APR_DECLARE(apr_status_t) apr_proc_wait_all_procs(apr_proc_t *proc,
+ apr_wait_t *status,
+ apr_wait_how_e waithow,
+ apr_pool_t *p)
{
- int waitpid_options = WUNTRACED;
-
- if (waithow != APR_WAIT) {
- waitpid_options |= WNOHANG;
- }
-
- if ((proc->pid = waitpid(-1, status, waitpid_options)) > 0) {
- return APR_CHILD_DONE;
- }
- else if (proc->pid == 0) {
- return APR_CHILD_NOTDONE;
- }
- return errno;
+ proc->pid = -1;
+ return apr_proc_wait(proc, status, waithow);
}
APR_DECLARE(apr_status_t) apr_proc_wait(apr_proc_t *proc,
@@ -384,18 +375,24 @@ APR_DECLARE(apr_status_t) apr_proc_wait(apr_proc_t *proc,
apr_wait_how_e waithow)
{
pid_t pstatus;
+ int waitpid_options = WUNTRACED;
+ int exit_int;
- if (waithow == APR_WAIT) {
- if ((pstatus = waitpid(proc->pid, exitcode, WUNTRACED)) > 0) {
- return APR_CHILD_DONE;
+ if (waithow != APR_WAIT) {
+ waitpid_options |= WNOHANG;
+ }
+
+ if ((pstatus = waitpid(proc->pid, &exit_int, waitpid_options)) > 0) {
+ if (proc->pid == -1) {
+ proc->pid = pstatus;
}
- else if (pstatus == 0) {
- return APR_CHILD_NOTDONE;
+ if (WIFEXITED(exit_int)) {
+ if (exitcode != NULL) {
+ *exitcode = WEXITSTATUS(exit_int);
+ }
+ return APR_CHILD_DONE;
}
- return errno;
- }
- if ((pstatus = waitpid(proc->pid, exitcode, WUNTRACED | WNOHANG)) > 0) {
- return APR_CHILD_DONE;
+ return APR_CHILD_NOTDONE;
}
else if (pstatus == 0) {
return APR_CHILD_NOTDONE;