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/rc.h | 58 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 27 deletions(-) (limited to 'sys/cmd/rc/rc.h') diff --git a/sys/cmd/rc/rc.h b/sys/cmd/rc/rc.h index 606ca7b..d3fc7bf 100644 --- a/sys/cmd/rc/rc.h +++ b/sys/cmd/rc/rc.h @@ -3,19 +3,6 @@ #include #include -/* - * A thread functions much like a GNU job -> it's just a simple execution stack - * We just need to modify the following datastructures: - * - * 1. Need to store the list of all "active" and "foreground" threads - * - Right now we just have Thread *proc which is the running process. - * - Need to move this to a linked list (how does this interact with the link?) - * - Linked list stores the independent roots of each individual process tree - * 2. Child pids are stored inside waitpid right now. Need to associate this more explictly with a thread. - * 3. Wait needs to be generalized to act on threads. - * 4. our "start" function is equivalent to the launch_job function - * 5. running the interpreter runs the launch_process implicitly (with forks called as interpreter functions) - */ // ----------------------------------------------------------------------- // types @@ -36,10 +23,28 @@ struct Io char *b, *e, buf[]; }; +enum +{ + Rappend, + Rwrite, + Rread, + Rhere, + Rdup, + Ropen, + Rclose, + Rrdwr +}; + struct Tree { int type; - char *str; + union{ + char *str; // Tword + struct { + ushort type; // Tpipe, Tredir, Tdup + int fd[2]; + } redir; + }; Tree *child[3]; Tree *link; }; @@ -79,13 +84,6 @@ struct Var Var *link; }; -enum -{ - Rclose, - Rdup, - Ropen, -}; - struct Redir { char type; /* what to do */ @@ -122,11 +120,14 @@ struct Thread List *args; // argument stack Var *local; // local variables - Redir *redir; // list of redirections + struct { + Redir *start; + Redir *end; + } redir; // list of redirections struct { - ushort i : 1; - ushort eof : 1; + ushort user : 1; + ushort eof : 1; } flag; struct { @@ -138,8 +139,8 @@ struct Thread int pid, pgid, status; long line; - Thread *link; // process we return to - Thread *next; // next job + Thread *caller; // process we return to + Thread *link; // next job }; struct Shell @@ -197,12 +198,15 @@ Tree *maketree2(int, Tree*, Tree*); Tree *maketree3(int, Tree*, Tree*, Tree*); Tree *token(int, char *); -Tree *hangchild1(Tree *, Tree *, int at); +Tree *hangchild1(Tree *, Tree *, int); +Tree *hangchild2(Tree *, Tree *, int, Tree *, int); +Tree *hangepilog(Tree *, Tree*); void freeparsetree(void); /* sys.c */ void initenv(void); +void redirect(struct Redir *); void execute(Word *, Word*); /* wait.c */ -- cgit v1.2.1