revert the probably-problematic part of the Plan 9-derived MI diff

(can't commit it into plan9 branch at the same time, CVS _does_
handle committing to two different branches, but not twice the
same file)
This commit is contained in:
tg
2006-08-28 01:25:33 +00:00
parent 606909d6f6
commit 70b490dac3

20
jobs.c
View File

@ -2,7 +2,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.10 2006/08/24 20:32:53 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.11 2006/08/28 01:25:33 tg Exp $");
/* Order important! */ /* Order important! */
#define PRUNNING 0 #define PRUNNING 0
@ -54,10 +54,8 @@ struct job {
pid_t pgrp; /* process group of job */ pid_t pgrp; /* process group of job */
pid_t ppid; /* pid of process that forked job */ pid_t ppid; /* pid of process that forked job */
int32_t age; /* number of jobs started */ int32_t age; /* number of jobs started */
#ifdef RUSAGE_CHILDREN
struct timeval systime; /* system time used by job */ struct timeval systime; /* system time used by job */
struct timeval usrtime; /* user time used by job */ struct timeval usrtime; /* user time used by job */
#endif
Proc *proc_list; /* process list */ Proc *proc_list; /* process list */
Proc *last_proc; /* last process in list */ Proc *last_proc; /* last process in list */
Coproc_id coproc_id; /* 0 or id of coprocess output pipe */ Coproc_id coproc_id; /* 0 or id of coprocess output pipe */
@ -85,9 +83,7 @@ static const char *const lookup_msgs[] = {
NULL NULL
}; };
#ifdef RUSAGE_CHILDREN
struct timeval j_systime, j_usrtime; /* user and system time of last j_waitjed job */ struct timeval j_systime, j_usrtime; /* user and system time of last j_waitjed job */
#endif
static Job *job_list; /* job list */ static Job *job_list; /* job list */
static Job *last_job; static Job *last_job;
@ -340,10 +336,8 @@ exchild(struct op *t, int flags,
*/ */
j->flags = (flags & XXCOM) ? JF_XXCOM : j->flags = (flags & XXCOM) ? JF_XXCOM :
((flags & XBGND) ? 0 : (JF_FG|JF_USETTYMODE)); ((flags & XBGND) ? 0 : (JF_FG|JF_USETTYMODE));
#ifdef RUSAGE_CHILDREN
timerclear(&j->usrtime); timerclear(&j->usrtime);
timerclear(&j->systime); timerclear(&j->systime);
#endif
j->state = PRUNNING; j->state = PRUNNING;
j->pgrp = 0; j->pgrp = 0;
j->ppid = procpid; j->ppid = procpid;
@ -995,10 +989,8 @@ j_waitj(Job *j,
trapsig(WTERMSIG(status)); trapsig(WTERMSIG(status));
} }
#ifdef RUSAGE_CHILDREN
j_usrtime = j->usrtime; j_usrtime = j->usrtime;
j_systime = j->systime; j_systime = j->systime;
#endif
rv = j->status; rv = j->status;
if (!(flags & JW_ASYNCNOTIFY) && if (!(flags & JW_ASYNCNOTIFY) &&
@ -1026,9 +1018,7 @@ j_sigchld(int sig __attribute__((unused)))
Proc *p = NULL; Proc *p = NULL;
int pid; int pid;
int status; int status;
#ifdef RUSAGE_CHILDREN
struct rusage ru0, ru1; struct rusage ru0, ru1;
#endif
/* Don't wait for any processes if a job is partially started. /* Don't wait for any processes if a job is partially started.
* This is so we don't do away with the process group leader * This is so we don't do away with the process group leader
@ -1041,18 +1031,14 @@ j_sigchld(int sig __attribute__((unused)))
return; return;
} }
#ifdef RUSAGE_CHILDREN
getrusage(RUSAGE_CHILDREN, &ru0); getrusage(RUSAGE_CHILDREN, &ru0);
#endif
do { do {
pid = waitpid(-1, &status, (WNOHANG|WUNTRACED)); pid = waitpid(-1, &status, (WNOHANG|WUNTRACED));
if (pid <= 0) /* return if would block (0) ... */ if (pid <= 0) /* return if would block (0) ... */
break; /* ... or no children or interrupted (-1) */ break; /* ... or no children or interrupted (-1) */
#ifdef RUSAGE_CHILDREN
getrusage(RUSAGE_CHILDREN, &ru1); getrusage(RUSAGE_CHILDREN, &ru1);
#endif
/* find job and process structures for this pid */ /* find job and process structures for this pid */
for (j = job_list; j != NULL; j = j->next) for (j = job_list; j != NULL; j = j->next)
@ -1065,19 +1051,15 @@ j_sigchld(int sig __attribute__((unused)))
warningf(true, "bad process waited for (pid = %d)", warningf(true, "bad process waited for (pid = %d)",
pid); pid);
*/ */
#ifdef RUSAGE_CHILDREN
ru0 = ru1; ru0 = ru1;
#endif
continue; continue;
} }
#ifdef RUSAGE_CHILDREN
timeradd(&j->usrtime, &ru1.ru_utime, &j->usrtime); timeradd(&j->usrtime, &ru1.ru_utime, &j->usrtime);
timersub(&j->usrtime, &ru0.ru_utime, &j->usrtime); timersub(&j->usrtime, &ru0.ru_utime, &j->usrtime);
timeradd(&j->systime, &ru1.ru_stime, &j->systime); timeradd(&j->systime, &ru1.ru_stime, &j->systime);
timersub(&j->systime, &ru0.ru_stime, &j->systime); timersub(&j->systime, &ru0.ru_stime, &j->systime);
ru0 = ru1; ru0 = ru1;
#endif
p->status = status; p->status = status;
if (WIFSTOPPED(status)) if (WIFSTOPPED(status))
p->state = PSTOPPED; p->state = PSTOPPED;