aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/rc/exec.c
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2021-12-04 14:10:21 -0800
committerNicholas Noll <nbnoll@eml.cc>2021-12-04 14:10:21 -0800
commit12e09f9f85ac48ff891adf92f3b2c9a5fea27273 (patch)
tree60051793885e9978dadf6672ef85cdda216676a2 /src/cmd/rc/exec.c
parentb80a3d28ce42be4fdec451f74620b10ee75219dc (diff)
Chore(REMOVE): finished deprecation of old io functions.
The old methods were simple wrappers of C standard library functions. We've moved (painfully) over to a new interface that allows for files to live on the stack. All users of the functionality are ported over.
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;