aboutsummaryrefslogtreecommitdiff
path: root/sys/cmd/rc/code.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/code.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/code.c')
-rw-r--r--sys/cmd/rc/code.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/sys/cmd/rc/code.c b/sys/cmd/rc/code.c
index 38cc06a..c5b1987 100644
--- a/sys/cmd/rc/code.c
+++ b/sys/cmd/rc/code.c
@@ -43,7 +43,7 @@ void
walk(Tree *node)
{
Tree *n;
- int addr;
+ int addr1, addr2;
if(!node)
return;
@@ -104,18 +104,18 @@ walk(Tree *node)
case '&':
emitf(Xasync);
- addr = emiti(0);
+ addr1 = emiti(0);
walk(node->child[0]);
emitf(Xexit);
- storepc(addr);
+ storepc(addr1);
break;
case Tsubshell:
emitf(Xsubshell);
- addr = emiti(0);
+ addr1 = emiti(0);
walk(node->child[0]);
emitf(Xexit);
- storepc(addr);
+ storepc(addr1);
break;
case Tbang:
@@ -132,6 +132,26 @@ walk(Tree *node)
walk(node->child[0]);
break;
+ case Tpipe:
+ emitf(Xpipe);
+
+ emiti(node->redir.fd[0]);
+ emiti(node->redir.fd[1]);
+ addr1 = emiti(0);
+ addr2 = emiti(0);
+
+ walk(node->child[0]);
+ emitf(Xexit);
+ storepc(addr1);
+
+ walk(node->child[1]);
+ emitf(Xreturn);
+ storepc(addr2);
+
+ emitf(Xpipewait);
+
+ break;
+
case '=':
for(n=node; node && node->type == '='; node = node->child[2])
;