From 888679027c2e9b43d1485d970df8170ac4fda29f Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Wed, 20 Oct 2021 13:10:54 -0700 Subject: Refactored interactivity to track with thread. Hit a bit of a stopping point. Specifically, the way XAsync runs currently is by forking the execution context and having the child run the async code while the parent runs the remainder. The problem with this architecture is it doesn't interact well with job control. When we fork, we create a new process group. Thus the Xasync fork becomes the new leader. In short, our traversal of the parse tree as to be less "preorder" and more "in order", i.e. from the leaves up. The "left" command of the pipeline should be the "leader" of the process group. --- sys/cmd/rc/job.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'sys/cmd/rc/job.c') 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; } -- cgit v1.2.1