aboutsummaryrefslogtreecommitdiff
path: root/sys/cmd/rc/job.c
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2021-10-20 13:10:54 -0700
committerNicholas Noll <nbnoll@eml.cc>2021-10-20 13:10:54 -0700
commit888679027c2e9b43d1485d970df8170ac4fda29f (patch)
treef46c257e6be1f47f4aa69d31a64643c76457a64b /sys/cmd/rc/job.c
parent6d50d5b97d49a74a8faf587ec2bbf234626adf0c (diff)
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.
Diffstat (limited to 'sys/cmd/rc/job.c')
-rw-r--r--sys/cmd/rc/job.c36
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;
}