aboutsummaryrefslogtreecommitdiff
path: root/sys/cmd/rc/rc.h
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/rc.h
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/rc.h')
-rw-r--r--sys/cmd/rc/rc.h58
1 files changed, 31 insertions, 27 deletions
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 <u.h>
#include <libn.h>
-/*
- * 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 */