aboutsummaryrefslogtreecommitdiff
path: root/sys/cmd/rc/rc.h
diff options
context:
space:
mode:
Diffstat (limited to 'sys/cmd/rc/rc.h')
-rw-r--r--sys/cmd/rc/rc.h65
1 files changed, 49 insertions, 16 deletions
diff --git a/sys/cmd/rc/rc.h b/sys/cmd/rc/rc.h
index 1c2aa6b..9c6307f 100644
--- a/sys/cmd/rc/rc.h
+++ b/sys/cmd/rc/rc.h
@@ -3,6 +3,19 @@
#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
@@ -14,8 +27,7 @@ typedef struct Tree Tree;
typedef struct Redir Redir;
typedef union Code Code;
typedef struct Thread Thread;
-
-typedef struct WaitMsg WaitMsg;
+typedef struct Shell Shell;
struct Io
{
@@ -86,7 +98,7 @@ struct Thread
struct {
int i;
Code *exe;
- } code; // execution stack
+ } code; // execution stack
struct {
Io *io;
char *path;
@@ -97,29 +109,39 @@ struct Thread
Redir *redir; // list of redirections
struct {
- ushort i : 1;
- ushort eof : 1;
+ ushort i : 1;
+ ushort eof : 1;
+ ushort stop : 1;
+ ushort done : 1;
+ ushort again : 1;
} flag; // flags for process
- int pid;
+ struct {
+ int len, cap, *pid;
+ } wait;
+
+ int pid, pgid, status;
long line;
Tree *nodes; // memory allocation
Thread *link; // process we return to
+ Thread *next; // next job
};
-struct WaitMsg
+struct Shell
{
- int pid; // of loved one
- ulong time[3]; // of loved one & descendants
- char *msg;
+ int pid;
+ int status;
+ int interactive;
+ Thread *jobs;
};
// -----------------------------------------------------------------------
// globals
-extern int rcpid;
-extern Thread *shell;
+extern Shell shell;
+
+extern Thread *proc;
extern Io *errio;
extern Code *compiled;
@@ -168,12 +190,23 @@ void freeparsetree(void);
/* sys.c */
void initenv(void);
+void execute(Word *, Word*);
-void addwait(int);
-void clearwait(void);
-int waitfor(int);
+/* wait.c */
+void addwait(Thread *, int);
+void clearwait(Thread*);
+int waitall(Thread *);
-void execute(Word *, Word*);
+void killzombies(void);
+
+/* job.c */
+Thread *getjob(int, int*);
+void addjob(Thread *);
+void deljob(Thread *);
+void report(Thread *, int);
+
+void foreground(Thread *, int);
+void background(Thread *, int);
/* exec.c */
// XXX: odd place for this