aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/rc/exec.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/rc/exec.c')
-rw-r--r--src/cmd/rc/exec.c56
1 files changed, 54 insertions, 2 deletions
diff --git a/src/cmd/rc/exec.c b/src/cmd/rc/exec.c
index bd68bf5..bdbc151 100644
--- a/src/cmd/rc/exec.c
+++ b/src/cmd/rc/exec.c
@@ -5,16 +5,20 @@
int yyparse(void);
-struct Builtin{
+struct Builtin
+{
char *name;
void (*func)(void);
};
-struct State {
+#if 0
+struct State
+{
int async;
};
static struct State state;
+#endif
// -----------------------------------------------------------------------
// globals
@@ -1415,6 +1419,54 @@ Xpipe(void)
}
void
+Xpipefd(void)
+{
+ char name[40];
+ Thread *orig = runner;
+ int pc, fd, pid, pfd[2], sidefd, mainfd;
+
+ pc = runner->code.i;
+ if(pipe(pfd)<0){
+ Xerror("can't get pipe");
+ return;
+ }
+
+ if(runner->code.exe[runner->code.i].i == Rread)
+ fd=1, sidefd=pfd[1], mainfd=pfd[0];
+ else
+ fd=0, sidefd=pfd[0], mainfd=pfd[1];
+
+ switch(pid = fork()){
+ case -1:
+ Xerror("try again");
+ break;
+ case 0:
+ initchild(runner,1);
+
+ /* child 0 (writer) forked process */
+ run(runner->code.exe, pc+2, runner->local, 1);
+
+ close(mainfd);
+ pushredir(Ropen, sidefd, fd);
+ runner->caller = nil;
+ break;
+
+ default:
+ initparent(runner,pid,0);
+
+ close(sidefd);
+ pushredir(Ropen, mainfd, mainfd);
+
+ strcpy(name, "/dev/fd/");
+ strĀ·itoa(name+8, mainfd);
+ pushword(name);
+
+ orig->code.i = orig->code.exe[pc+1].i;
+ break;
+ }
+}
+
+void
Xbasic(void)
{
Var *v;