version 1.10, 2001/11/19 19:02:15 |
version 1.11, 2002/06/12 06:07:16 |
|
|
{ |
{ |
CHILD *pc, *prevpc; |
CHILD *pc, *prevpc; |
|
|
debugmsg(DM_CALL, "removechild(%s, %d, %d) start", |
debugmsg(DM_CALL, "removechild(%s, %ld, %d) start", |
child->c_name, child->c_pid, child->c_readfd); |
child->c_name, (long)child->c_pid, child->c_readfd); |
|
|
/* |
/* |
* Find the child in the list |
* Find the child in the list |
|
|
break; |
break; |
|
|
if (pc == NULL) |
if (pc == NULL) |
error("RemoveChild called with bad child %s %d %d", |
error("RemoveChild called with bad child %s %ld %d", |
child->c_name, child->c_pid, child->c_readfd); |
child->c_name, (long)child->c_pid, child->c_readfd); |
else { |
else { |
/* |
/* |
* Remove the child |
* Remove the child |
|
|
++activechildren; |
++activechildren; |
|
|
debugmsg(DM_MISC, |
debugmsg(DM_MISC, |
"addchild() created '%s' pid %d fd %d (active=%d)\n", |
"addchild() created '%s' pid %ld fd %d (active=%d)\n", |
child->c_name, child->c_pid, child->c_readfd, activechildren); |
child->c_name, (long)child->c_pid, child->c_readfd, |
|
activechildren); |
} |
} |
|
|
/* |
/* |
|
|
char rbuf[BUFSIZ]; |
char rbuf[BUFSIZ]; |
int amt; |
int amt; |
|
|
debugmsg(DM_CALL, "[readchild(%s, %d, %d) start]", |
debugmsg(DM_CALL, "[readchild(%s, %ld, %d) start]", |
child->c_name, child->c_pid, child->c_readfd); |
child->c_name, (long)child->c_pid, child->c_readfd); |
|
|
/* |
/* |
* Check that this is a valid child. |
* Check that this is a valid child. |
*/ |
*/ |
if (child->c_name == NULL || child->c_readfd <= 0) { |
if (child->c_name == NULL || child->c_readfd <= 0) { |
debugmsg(DM_MISC, "[readchild(%s, %d, %d) bad child]", |
debugmsg(DM_MISC, "[readchild(%s, %ld, %d) bad child]", |
child->c_name, child->c_pid, child->c_readfd); |
child->c_name, (long)child->c_pid, child->c_readfd); |
return; |
return; |
} |
} |
|
|
|
|
*/ |
*/ |
while ((amt = read(child->c_readfd, rbuf, sizeof(rbuf))) > 0) { |
while ((amt = read(child->c_readfd, rbuf, sizeof(rbuf))) > 0) { |
/* XXX remove these debug calls */ |
/* XXX remove these debug calls */ |
debugmsg(DM_MISC, "[readchild(%s, %d, %d) got %d bytes]", |
debugmsg(DM_MISC, "[readchild(%s, %ld, %d) got %d bytes]", |
child->c_name, child->c_pid, child->c_readfd, amt); |
child->c_name, (long)child->c_pid, child->c_readfd, amt); |
|
|
(void) xwrite(fileno(stdout), rbuf, amt); |
(void) xwrite(fileno(stdout), rbuf, amt); |
|
|
debugmsg(DM_MISC, "[readchild(%s, %d, %d) write done]", |
debugmsg(DM_MISC, "[readchild(%s, %ld, %d) write done]", |
child->c_name, child->c_pid, child->c_readfd); |
child->c_name, (long)child->c_pid, child->c_readfd); |
} |
} |
|
|
debugmsg(DM_MISC, "readchild(%s, %d, %d) done: amt = %d errno = %d\n", |
debugmsg(DM_MISC, "readchild(%s, %ld, %d) done: amt = %d errno = %d\n", |
child->c_name, child->c_pid, child->c_readfd, amt, errno); |
child->c_name, (long)child->c_pid, child->c_readfd, amt, errno); |
|
|
/* |
/* |
* See if we've reached EOF |
* See if we've reached EOF |
*/ |
*/ |
if (amt == 0) |
if (amt == 0) |
debugmsg(DM_MISC, "readchild(%s, %d, %d) at EOF\n", |
debugmsg(DM_MISC, "readchild(%s, %ld, %d) at EOF\n", |
child->c_name, child->c_pid, child->c_readfd); |
child->c_name, (long)child->c_pid, child->c_readfd); |
} |
} |
|
|
/* |
/* |
|
|
* a process does exit, then the pointer "statval" is set to the |
* a process does exit, then the pointer "statval" is set to the |
* exit status of the exiting process, if statval is not NULL. |
* exit status of the exiting process, if statval is not NULL. |
*/ |
*/ |
static int waitproc(statval, block) |
static pid_t waitproc(statval, block) |
int *statval; |
int *statval; |
int block; |
int block; |
{ |
{ |
WAIT_ARG_TYPE status; |
WAIT_ARG_TYPE status; |
int pid, exitval; |
int exitval; |
|
pid_t pid; |
|
|
debugmsg(DM_CALL, "waitproc() %s, active children = %d...\n", |
debugmsg(DM_CALL, "waitproc() %s, active children = %d...\n", |
(block) ? "blocking" : "nonblocking", activechildren); |
(block) ? "blocking" : "nonblocking", activechildren); |
|
|
if (pid > 0 && exitval != 0) { |
if (pid > 0 && exitval != 0) { |
nerrs++; |
nerrs++; |
debugmsg(DM_MISC, |
debugmsg(DM_MISC, |
"Child process %d exited with status %d.\n", |
"Child process %ld exited with status %d.\n", |
pid, exitval); |
(long)pid, exitval); |
} |
} |
|
|
if (statval) |
if (statval) |
|
|
*/ |
*/ |
pid = waitproc(&status, FALSE); |
pid = waitproc(&status, FALSE); |
debugmsg(DM_MISC, |
debugmsg(DM_MISC, |
"reap() pid = %d status = %d activechildren=%d\n", |
"reap() pid = %ld status = %d activechildren=%d\n", |
pid, status, activechildren); |
(long)pid, status, activechildren); |
|
|
/* |
/* |
* See if a child really exited |
* See if a child really exited |
|
|
if (pc->c_name && kill(pc->c_pid, 0) < 0 && |
if (pc->c_name && kill(pc->c_pid, 0) < 0 && |
errno == ESRCH) { |
errno == ESRCH) { |
debugmsg(DM_MISC, |
debugmsg(DM_MISC, |
"waitup() proc %d (%s) died unexpectedly!", |
"waitup() proc %ld (%s) died unexpectedly!", |
pc->c_pid, pc->c_name); |
(long)pc->c_pid, pc->c_name); |
pc->c_state = PSdead; |
pc->c_state = PSdead; |
needscan = TRUE; |
needscan = TRUE; |
} |
} |