bjh 99/06/06 06:54:56
Modified: apr/threadproc/os2 proc.c threadproc.h Log: Add flag in proc_t to prevent errors waiting for children that never lived or have already been waited for. This can happen in testsock.c if client & server don't end at the same time, causing it to loop forever. Revision Changes Path 1.2 +19 -3 apache-apr/apr/threadproc/os2/proc.c Index: proc.c =================================================================== RCS file: /home/cvs/apache-apr/apr/threadproc/os2/proc.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- proc.c 1999/06/06 07:15:21 1.1 +++ proc.c 1999/06/06 13:54:54 1.2 @@ -137,14 +137,16 @@ if ((pid = fork()) < 0) { return errno; - } - else if (pid == 0) { + } else if (pid == 0) { (*proc)->pid = pid; (*proc)->attr = NULL; + (*proc)->running = TRUE; return APR_INCHILD; } + (*proc)->pid = pid; (*proc)->attr = NULL; + (*proc)->running = TRUE; return APR_INPARENT; } @@ -153,6 +155,7 @@ struct procattr_t *attr, struct proc_t **new) { int i; + ap_status_t stat; char **newargs; char savedir[300]; HFILE save_in, save_out, save_err, dup; @@ -165,6 +168,7 @@ } (*new)->cntxt = cont; + (*new)->running = FALSE; /* Prevent other threads from running while these process-wide resources are modified */ if (attr->child_in || attr->child_out || attr->child_err || attr->currdir) { @@ -229,6 +233,8 @@ (*new)->pid = spawnve(P_NOWAIT, progname, args, env); } + stat = (*new)->pid < 0 ? errno : APR_SUCCESS; + if (attr->currdir != NULL) { chdir(savedir); } @@ -239,12 +245,14 @@ DosDupHandle(save_in, &dup); DosClose(save_in); } + if (attr->child_out) { ap_close(attr->child_out); dup = STDOUT_FILENO; DosDupHandle(save_out, &dup); DosClose(save_out); } + if (attr->child_err) { ap_close(attr->child_err); dup = STDERR_FILENO; @@ -256,9 +264,12 @@ DosExitCritSec(); (*new)->attr = attr; - return APR_SUCCESS; + (*new)->running = stat == APR_SUCCESS; + return stat; } + + ap_status_t ap_get_childin(struct proc_t *proc, ap_file_t **new) { (*new) = proc->attr->parent_in; @@ -285,8 +296,12 @@ if (!proc) return APR_ENOPROC; + if (!proc->running) + return APR_CHILD_DONE; + if (wait == APR_WAIT) { if ((stat = waitpid(proc->pid, NULL, WUNTRACED)) > 0) { + proc->running = FALSE; return APR_CHILD_DONE; } else if (stat == 0) { return APR_CHILD_NOTDONE; @@ -295,6 +310,7 @@ } if ((stat = waitpid(proc->pid, NULL, WUNTRACED | WNOHANG)) > 0) { + proc->running = FALSE; return APR_CHILD_DONE; } else if (stat == 0) { return APR_CHILD_NOTDONE; 1.2 +1 -0 apache-apr/apr/threadproc/os2/threadproc.h Index: threadproc.h =================================================================== RCS file: /home/cvs/apache-apr/apr/threadproc/os2/threadproc.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- threadproc.h 1999/06/06 07:15:23 1.1 +++ threadproc.h 1999/06/06 13:54:55 1.2 @@ -99,6 +99,7 @@ ap_context_t *cntxt; pid_t pid; struct procattr_t *attr; + int running; }; typedef void (*os2_thread_start_t)(void *);