diff options
Diffstat (limited to 'sys/cmd/rc/job.c')
-rw-r--r-- | sys/cmd/rc/job.c | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/sys/cmd/rc/job.c b/sys/cmd/rc/job.c index a8747e9..1587951 100644 --- a/sys/cmd/rc/job.c +++ b/sys/cmd/rc/job.c @@ -11,7 +11,7 @@ getjob(int pid, int *index) { int i; Thread *job; - for(i=0,job=shell.jobs; job && job->pid != pid; i++, job=job->next) + for(i=0,job=shell.jobs; job && job->pid != pid; i++, job=job->link) ; return job; @@ -39,34 +39,42 @@ report(Thread *job, int index) } void -wakeup(Thread *t) +wakeup(Thread *job) { int i; - t->wait.status = Prun; - for(i=0; i < t->wait.len; i++){ - if(t->wait.on[i].status == Pstop) - t->wait.on[i].status = Prun; + job->wait.status = Prun; + for(i=0; i < job->wait.len; i++){ + if(job->wait.on[i].status == Pstop) + job->wait.on[i].status = Prun; } + + tcsetpgrp(0, job->pgid); } void -foreground(Thread *job, int signal) +foreground(Thread *job, int now) { - tcsetpgrp(0, job->pgid); - if(signal){ + Thread *caller = job->caller; + if(now){ if(kill(-job->pgid, SIGCONT) < 0) perror("kill[SIGCONT]"); } waitall(job); - - tcsetpgrp(0, shell.pid); + /* + * reset state if we have a caller + * otherwise we will exit anyways + */ + if(caller && caller->flag.user){ + tcsetpgrp(0, caller->pid); + job->flag.user = 1; + } } void addjob(Thread *job) { - job->next = shell.jobs; + job->link = shell.jobs; shell.jobs = job; job->wait.status = Prun; } @@ -76,8 +84,8 @@ deljob(Thread *job) { Thread **jp; - for(jp = &shell.jobs; *jp && *jp != job; jp = &(*jp)->next) + for(jp = &shell.jobs; *jp && *jp != job; jp = &(*jp)->link) ; - *jp = job->next; + *jp = job->link; } |