version 1.50, 2002/03/19 00:08:31 |
version 1.51, 2002/06/12 06:07:16 |
|
|
*/ |
*/ |
#define JOB_BUFSIZE 1024 |
#define JOB_BUFSIZE 1024 |
typedef struct Job_ { |
typedef struct Job_ { |
int pid; /* The child's process ID */ |
pid_t pid; /* The child's process ID */ |
GNode *node; /* The target the child is making */ |
GNode *node; /* The target the child is making */ |
LstNode tailCmds; /* The node of the first command to be |
LstNode tailCmds; /* The node of the first command to be |
* saved when the job has been run */ |
* saved when the job has been run */ |
|
|
int signo = *(int *)signop; |
int signo = *(int *)signop; |
if (DEBUG(JOB)) { |
if (DEBUG(JOB)) { |
(void)fprintf(stdout, |
(void)fprintf(stdout, |
"JobCondPassSig passing signal %d to child %d.\n", |
"JobCondPassSig passing signal %d to child %ld.\n", |
signo, job->pid); |
signo, (long)job->pid); |
(void)fflush(stdout); |
(void)fflush(stdout); |
} |
} |
KILL(job->pid, signo); |
KILL(job->pid, signo); |
|
|
void *job; /* job to examine */ |
void *job; /* job to examine */ |
void *pid; /* process id desired */ |
void *pid; /* process id desired */ |
{ |
{ |
return *(int *)pid - ((Job *)job)->pid; |
return *(pid_t *)pid - ((Job *)job)->pid; |
} |
} |
|
|
/*- |
/*- |
|
|
|
|
if (WIFEXITED(*status)) { |
if (WIFEXITED(*status)) { |
if (DEBUG(JOB)) { |
if (DEBUG(JOB)) { |
(void)fprintf(stdout, "Process %d exited.\n", job->pid); |
(void)fprintf(stdout, "Process %ld exited.\n", (long)job->pid); |
(void)fflush(stdout); |
(void)fflush(stdout); |
} |
} |
if (WEXITSTATUS(*status) != 0) { |
if (WEXITSTATUS(*status) != 0) { |
|
|
} |
} |
} else if (WIFSTOPPED(*status)) { |
} else if (WIFSTOPPED(*status)) { |
if (DEBUG(JOB)) { |
if (DEBUG(JOB)) { |
(void)fprintf(stdout, "Process %d stopped.\n", job->pid); |
(void)fprintf(stdout, "Process %ld stopped.\n", (long)job->pid); |
(void)fflush(stdout); |
(void)fflush(stdout); |
} |
} |
if (usePipes && job->node != lastNode) { |
if (usePipes && job->node != lastNode) { |
|
|
if (!(job->flags & JOB_CONTINUING)) { |
if (!(job->flags & JOB_CONTINUING)) { |
if (DEBUG(JOB)) { |
if (DEBUG(JOB)) { |
(void)fprintf(stdout, |
(void)fprintf(stdout, |
"Warning: process %d was not continuing.\n", |
"Warning: process %ld was not continuing.\n", |
job->pid); |
(long)job->pid); |
(void)fflush(stdout); |
(void)fflush(stdout); |
} |
} |
#ifdef notdef |
#ifdef notdef |
|
|
nJobs += 1; |
nJobs += 1; |
if (DEBUG(JOB)) { |
if (DEBUG(JOB)) { |
(void)fprintf(stdout, |
(void)fprintf(stdout, |
"Process %d is continuing locally.\n", |
"Process %ld is continuing locally.\n", |
job->pid); |
(long)job->pid); |
(void)fflush(stdout); |
(void)fflush(stdout); |
} |
} |
nLocal += 1; |
nLocal += 1; |
|
|
Job *job; /* Job to execute */ |
Job *job; /* Job to execute */ |
char **argv; |
char **argv; |
{ |
{ |
int cpid; /* ID of new child */ |
pid_t cpid; /* ID of new child */ |
|
|
if (DEBUG(JOB)) { |
if (DEBUG(JOB)) { |
int i; |
int i; |
|
|
Job_CatchChildren(block) |
Job_CatchChildren(block) |
bool block; /* true if should block on the wait. */ |
bool block; /* true if should block on the wait. */ |
{ |
{ |
int pid; /* pid of dead child */ |
pid_t pid; /* pid of dead child */ |
Job *job; /* job descriptor for dead child */ |
Job *job; /* job descriptor for dead child */ |
LstNode jnode; /* list element for finding job */ |
LstNode jnode; /* list element for finding job */ |
int status; /* Exit/termination status */ |
int status; /* Exit/termination status */ |
|
|
(block?0:WNOHANG)|WUNTRACED)) > 0) |
(block?0:WNOHANG)|WUNTRACED)) > 0) |
{ |
{ |
if (DEBUG(JOB)) { |
if (DEBUG(JOB)) { |
(void)fprintf(stdout, "Process %d exited or stopped.\n", pid); |
(void)fprintf(stdout, "Process %ld exited or stopped.\n", (long)pid); |
(void)fflush(stdout); |
(void)fflush(stdout); |
} |
} |
|
|
|
|
if (WIFSIGNALED(status) && (WTERMSIG(status) == SIGCONT)) { |
if (WIFSIGNALED(status) && (WTERMSIG(status) == SIGCONT)) { |
jnode = Lst_Find(&stoppedJobs, JobCmpPid, &pid); |
jnode = Lst_Find(&stoppedJobs, JobCmpPid, &pid); |
if (jnode == NULL) { |
if (jnode == NULL) { |
Error("Resumed child (%d) not in table", pid); |
Error("Resumed child (%ld) not in table", (long)pid); |
continue; |
continue; |
} |
} |
job = (Job *)Lst_Datum(jnode); |
job = (Job *)Lst_Datum(jnode); |
Lst_Remove(&stoppedJobs, jnode); |
Lst_Remove(&stoppedJobs, jnode); |
} else { |
} else { |
Error("Child (%d) not in table?", pid); |
Error("Child (%ld) not in table?", (long)pid); |
continue; |
continue; |
} |
} |
} else { |
} else { |
|
|
if (job->pid) { |
if (job->pid) { |
if (DEBUG(JOB)) { |
if (DEBUG(JOB)) { |
(void)fprintf(stdout, |
(void)fprintf(stdout, |
"JobInterrupt passing signal to child %d.\n", |
"JobInterrupt passing signal to child %ld.\n", |
job->pid); |
(long)job->pid); |
(void)fflush(stdout); |
(void)fflush(stdout); |
} |
} |
KILL(job->pid, signo); |
KILL(job->pid, signo); |
|
|
/* |
/* |
* Catch as many children as want to report in at first, then give up |
* Catch as many children as want to report in at first, then give up |
*/ |
*/ |
while (waitpid((pid_t) -1, &foo, WNOHANG) > 0) |
while (waitpid(-1, &foo, WNOHANG) > 0) |
continue; |
continue; |
(void)eunlink(tfile); |
(void)eunlink(tfile); |
} |
} |