summaryrefslogtreecommitdiff
path: root/sys/src/cmd/mothra/mothra.c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@gmx.de>2013-10-04 21:11:56 +0200
committercinap_lenrek <cinap_lenrek@gmx.de>2013-10-04 21:11:56 +0200
commit6187e219da80ed8d75c717cd5f7c2f10326c5a81 (patch)
treeffaacc9e80f6cda4a8b04df5f0a2e5949a33eae9 /sys/src/cmd/mothra/mothra.c
parent0b42409cf44168a945cfa5080f71b61be618beb9 (diff)
mothra: avoid intermediate rc shell processes, use rfork(RFREND) to isolate rendezvous group
Diffstat (limited to 'sys/src/cmd/mothra/mothra.c')
-rw-r--r--sys/src/cmd/mothra/mothra.c30
1 files changed, 20 insertions, 10 deletions
diff --git a/sys/src/cmd/mothra/mothra.c b/sys/src/cmd/mothra/mothra.c
index 6ea1b850e..f40d22960 100644
--- a/sys/src/cmd/mothra/mothra.c
+++ b/sys/src/cmd/mothra/mothra.c
@@ -747,8 +747,8 @@ void dolink(Panel *p, int buttons, Rtext *word){
}
}
-void filter(char *cmd, int fd){
- switch(rfork(RFFDG|RFPROC|RFMEM|RFNOWAIT|RFNOTEG)){
+void filter(int fd, char *cmd){
+ switch(rfork(RFFDG|RFPROC|RFMEM|RFREND|RFNOWAIT|RFNOTEG)){
case -1:
message("Can't fork!");
break;
@@ -820,24 +820,34 @@ dupfds(int fd, ...)
free(dir);
}
-int pipeline(char *cmd, int fd)
+int pipeline(int fd, char *fmt, ...)
{
+ char buf[80], *argv[4];
+ va_list arg;
int pfd[2];
- if(pipe(pfd)==-1){
-Err:
+ va_start(arg, fmt);
+ vsnprint(buf, sizeof buf, fmt, arg);
+ va_end(arg);
+
+ if(pipe(pfd) < 0){
+ Err:
close(fd);
- werrstr("pipeline for %s failed: %r", cmd);
+ werrstr("pipeline for %s failed: %r", buf);
return -1;
}
- switch(rfork(RFFDG|RFPROC|RFMEM|RFNOWAIT)){
+ switch(rfork(RFPROC|RFMEM|RFFDG|RFREND|RFNOWAIT)){
case -1:
close(pfd[0]);
close(pfd[1]);
goto Err;
case 0:
dupfds(fd, pfd[1], 2, -1);
- execl("/bin/rc", "rc", "-c", cmd, 0);
+ argv[0] = "rc";
+ argv[1] = "-c";
+ argv[2] = buf;
+ argv[3] = nil;
+ exec("/bin/rc", argv);
_exits(0);
}
close(fd);
@@ -920,7 +930,7 @@ void geturl(char *urlname, int post, int plumb, int map){
save(fd, cmd);
break;
case HTML:
- fd = pipeline("/bin/uhtml", fd);
+ fd = pipeline(fd, "exec uhtml");
case PLAIN:
n=0;
for(i=wwwtop-1; i>=0 && i!=(wwwtop-NWWW-1); i--){
@@ -969,7 +979,7 @@ void geturl(char *urlname, int post, int plumb, int map){
case PNG:
case BMP:
case PAGE:
- filter("page -w", fd);
+ filter(fd, "exec page -w");
break;
}
break;