summaryrefslogtreecommitdiff
path: root/sys/src/cmd/mothra
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
parent0b42409cf44168a945cfa5080f71b61be618beb9 (diff)
mothra: avoid intermediate rc shell processes, use rfork(RFREND) to isolate rendezvous group
Diffstat (limited to 'sys/src/cmd/mothra')
-rw-r--r--sys/src/cmd/mothra/getpix.c17
-rw-r--r--sys/src/cmd/mothra/mothra.c30
-rw-r--r--sys/src/cmd/mothra/mothra.h2
-rw-r--r--sys/src/cmd/mothra/url.c6
4 files changed, 31 insertions, 24 deletions
diff --git a/sys/src/cmd/mothra/getpix.c b/sys/src/cmd/mothra/getpix.c
index 9a56c8a44..5dd31bb01 100644
--- a/sys/src/cmd/mothra/getpix.c
+++ b/sys/src/cmd/mothra/getpix.c
@@ -28,7 +28,7 @@ void getimage(Rtext *t, Www *w){
Url url;
Image *b;
int fd, typ;
- char err[512];
+ char err[512], buf[80], *s;
Pix *p;
ap=t->user;
@@ -54,19 +54,16 @@ void getimage(Rtext *t, Www *w){
werrstr("unknown image type");
goto Err;
}
- if((fd = pipeline(pixcmd[typ], fd)) < 0)
+ if((fd = pipeline(fd, "exec %s", pixcmd[typ])) < 0)
goto Err;
if(ap->width>0 || ap->height>0){
- char buf[80];
- char *p;
-
- p = buf;
- p += sprint(p, "resize");
+ s = buf;
+ s += sprint(s, "exec resize");
if(ap->width>0)
- p += sprint(p, " -x %d", ap->width);
+ s += sprint(s, " -x %d", ap->width);
if(ap->height>0)
- p += sprint(p, " -y %d", ap->height);
- if((fd = pipeline(buf, fd)) < 0)
+ s += sprint(s, " -y %d", ap->height);
+ if((fd = pipeline(fd, buf)) < 0)
goto Err;
}
b=readimage(display, fd, 1);
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;
diff --git a/sys/src/cmd/mothra/mothra.h b/sys/src/cmd/mothra/mothra.h
index b38391338..ef0c44f1a 100644
--- a/sys/src/cmd/mothra/mothra.h
+++ b/sys/src/cmd/mothra/mothra.h
@@ -88,7 +88,7 @@ void getpix(Rtext *, Www *);
ulong countpix(void *p);
void freepix(void *p);
void dupfds(int fd, ...);
-int pipeline(char *, int);
+int pipeline(int fd, char *fmt, ...);
void getfonts(void);
void *emalloc(int);
void nstrcpy(char *to, char *from, int len);
diff --git a/sys/src/cmd/mothra/url.c b/sys/src/cmd/mothra/url.c
index 5bb4736b9..dd2ea4ad3 100644
--- a/sys/src/cmd/mothra/url.c
+++ b/sys/src/cmd/mothra/url.c
@@ -143,11 +143,11 @@ urlget(Url *url, int body)
readstr(buf, buf, sizeof(buf));
if(!cistrcmp(buf, "compress"))
- fd = pipeline("/bin/uncompress", fd);
+ fd = pipeline(fd, "exec uncompress");
else if(!cistrcmp(buf, "gzip"))
- fd = pipeline("/bin/gunzip", fd);
+ fd = pipeline(fd, "exec gunzip");
else if(!cistrcmp(buf, "bzip2"))
- fd = pipeline("/bin/bunzip2", fd);
+ fd = pipeline(fd, "exec bunzip2");
return fd;
}