aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/rc
diff options
context:
space:
mode:
authorMichael Teichgräber <mt4swm@googlemail.com>2009-09-13 18:26:51 -0400
committerMichael Teichgräber <mt4swm@googlemail.com>2009-09-13 18:26:51 -0400
commit38b62735e4e151b626c46dd284d19fb6b0b3f59b (patch)
tree14c365189a26d0c1c550e1e649242774bfaf38f8 /src/cmd/rc
parent7a7e8ed6b227902528cf8a6bc594bee842d0ea90 (diff)
downloadplan9port-38b62735e4e151b626c46dd284d19fb6b0b3f59b.tar.gz
plan9port-38b62735e4e151b626c46dd284d19fb6b0b3f59b.tar.bz2
plan9port-38b62735e4e151b626c46dd284d19fb6b0b3f59b.zip
rc: implement and document <>{cmd} notation
http://codereview.appspot.com/105061
Diffstat (limited to 'src/cmd/rc')
-rw-r--r--src/cmd/rc/havefork.c64
1 files changed, 47 insertions, 17 deletions
diff --git a/src/cmd/rc/havefork.c b/src/cmd/rc/havefork.c
index 62d52c2c..74abfe17 100644
--- a/src/cmd/rc/havefork.c
+++ b/src/cmd/rc/havefork.c
@@ -177,18 +177,33 @@ Xpipefd(void)
int pc = p->pc, pid;
char name[40];
int pfd[2];
- int sidefd, mainfd;
- if(pipe(pfd)<0){
- Xerror("can't get pipe");
- return;
+ struct { int sidefd, mainfd; } fd[2], *r, *w;
+
+ r = &fd[0];
+ w = &fd[1];
+ switch(p->code[pc].i){
+ case READ:
+ w = nil;
+ break;
+ case WRITE:
+ r = nil;
}
- if(p->code[pc].i==READ){
- sidefd = pfd[PWR];
- mainfd = pfd[PRD];
+
+ if(r){
+ if(pipe(pfd)<0){
+ Xerror("can't get pipe");
+ return;
+ }
+ r->sidefd = pfd[PWR];
+ r->mainfd = pfd[PRD];
}
- else{
- sidefd = pfd[PRD];
- mainfd = pfd[PWR];
+ if(w){
+ if(pipe(pfd)<0){
+ Xerror("can't get pipe");
+ return;
+ }
+ w->sidefd = pfd[PRD];
+ w->mainfd = pfd[PWR];
}
switch(pid = fork()){
case -1:
@@ -197,17 +212,32 @@ Xpipefd(void)
case 0:
clearwaitpids();
start(p->code, pc+2, runq->local);
- close(mainfd);
- pushredir(ROPEN, sidefd, p->code[pc].i==READ?1:0);
+ if(r){
+ close(r->mainfd);
+ pushredir(ROPEN, r->sidefd, 1);
+ }
+ if(w){
+ close(w->mainfd);
+ pushredir(ROPEN, w->sidefd, 0);
+ }
runq->ret = 0;
break;
default:
addwaitpid(pid);
- close(sidefd);
- pushredir(ROPEN, mainfd, mainfd); /* isn't this a noop? */
- strcpy(name, Fdprefix);
- inttoascii(name+strlen(name), mainfd);
- pushword(name);
+ if(w){
+ close(w->sidefd);
+ pushredir(ROPEN, w->mainfd, w->mainfd); /* so that Xpopredir can close it later */
+ strcpy(name, Fdprefix);
+ inttoascii(name+strlen(name), w->mainfd);
+ pushword(name);
+ }
+ if(r){
+ close(r->sidefd);
+ pushredir(ROPEN, r->mainfd, r->mainfd);
+ strcpy(name, Fdprefix);
+ inttoascii(name+strlen(name), r->mainfd);
+ pushword(name);
+ }
p->pc = p->code[pc+1].i;
break;
}