mothra: avoid intermediate rc shell processes, use rfork(RFREND) to isolate rendezvous group
This commit is contained in:
parent
0b42409cf4
commit
6187e219da
4 changed files with 31 additions and 24 deletions
|
@ -28,7 +28,7 @@ void getimage(Rtext *t, Www *w){
|
||||||
Url url;
|
Url url;
|
||||||
Image *b;
|
Image *b;
|
||||||
int fd, typ;
|
int fd, typ;
|
||||||
char err[512];
|
char err[512], buf[80], *s;
|
||||||
Pix *p;
|
Pix *p;
|
||||||
|
|
||||||
ap=t->user;
|
ap=t->user;
|
||||||
|
@ -54,19 +54,16 @@ void getimage(Rtext *t, Www *w){
|
||||||
werrstr("unknown image type");
|
werrstr("unknown image type");
|
||||||
goto Err;
|
goto Err;
|
||||||
}
|
}
|
||||||
if((fd = pipeline(pixcmd[typ], fd)) < 0)
|
if((fd = pipeline(fd, "exec %s", pixcmd[typ])) < 0)
|
||||||
goto Err;
|
goto Err;
|
||||||
if(ap->width>0 || ap->height>0){
|
if(ap->width>0 || ap->height>0){
|
||||||
char buf[80];
|
s = buf;
|
||||||
char *p;
|
s += sprint(s, "exec resize");
|
||||||
|
|
||||||
p = buf;
|
|
||||||
p += sprint(p, "resize");
|
|
||||||
if(ap->width>0)
|
if(ap->width>0)
|
||||||
p += sprint(p, " -x %d", ap->width);
|
s += sprint(s, " -x %d", ap->width);
|
||||||
if(ap->height>0)
|
if(ap->height>0)
|
||||||
p += sprint(p, " -y %d", ap->height);
|
s += sprint(s, " -y %d", ap->height);
|
||||||
if((fd = pipeline(buf, fd)) < 0)
|
if((fd = pipeline(fd, buf)) < 0)
|
||||||
goto Err;
|
goto Err;
|
||||||
}
|
}
|
||||||
b=readimage(display, fd, 1);
|
b=readimage(display, fd, 1);
|
||||||
|
|
|
@ -747,8 +747,8 @@ void dolink(Panel *p, int buttons, Rtext *word){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void filter(char *cmd, int fd){
|
void filter(int fd, char *cmd){
|
||||||
switch(rfork(RFFDG|RFPROC|RFMEM|RFNOWAIT|RFNOTEG)){
|
switch(rfork(RFFDG|RFPROC|RFMEM|RFREND|RFNOWAIT|RFNOTEG)){
|
||||||
case -1:
|
case -1:
|
||||||
message("Can't fork!");
|
message("Can't fork!");
|
||||||
break;
|
break;
|
||||||
|
@ -820,24 +820,34 @@ dupfds(int fd, ...)
|
||||||
free(dir);
|
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];
|
int pfd[2];
|
||||||
|
|
||||||
if(pipe(pfd)==-1){
|
va_start(arg, fmt);
|
||||||
|
vsnprint(buf, sizeof buf, fmt, arg);
|
||||||
|
va_end(arg);
|
||||||
|
|
||||||
|
if(pipe(pfd) < 0){
|
||||||
Err:
|
Err:
|
||||||
close(fd);
|
close(fd);
|
||||||
werrstr("pipeline for %s failed: %r", cmd);
|
werrstr("pipeline for %s failed: %r", buf);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
switch(rfork(RFFDG|RFPROC|RFMEM|RFNOWAIT)){
|
switch(rfork(RFPROC|RFMEM|RFFDG|RFREND|RFNOWAIT)){
|
||||||
case -1:
|
case -1:
|
||||||
close(pfd[0]);
|
close(pfd[0]);
|
||||||
close(pfd[1]);
|
close(pfd[1]);
|
||||||
goto Err;
|
goto Err;
|
||||||
case 0:
|
case 0:
|
||||||
dupfds(fd, pfd[1], 2, -1);
|
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);
|
_exits(0);
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
|
@ -920,7 +930,7 @@ void geturl(char *urlname, int post, int plumb, int map){
|
||||||
save(fd, cmd);
|
save(fd, cmd);
|
||||||
break;
|
break;
|
||||||
case HTML:
|
case HTML:
|
||||||
fd = pipeline("/bin/uhtml", fd);
|
fd = pipeline(fd, "exec uhtml");
|
||||||
case PLAIN:
|
case PLAIN:
|
||||||
n=0;
|
n=0;
|
||||||
for(i=wwwtop-1; i>=0 && i!=(wwwtop-NWWW-1); i--){
|
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 PNG:
|
||||||
case BMP:
|
case BMP:
|
||||||
case PAGE:
|
case PAGE:
|
||||||
filter("page -w", fd);
|
filter(fd, "exec page -w");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -88,7 +88,7 @@ void getpix(Rtext *, Www *);
|
||||||
ulong countpix(void *p);
|
ulong countpix(void *p);
|
||||||
void freepix(void *p);
|
void freepix(void *p);
|
||||||
void dupfds(int fd, ...);
|
void dupfds(int fd, ...);
|
||||||
int pipeline(char *, int);
|
int pipeline(int fd, char *fmt, ...);
|
||||||
void getfonts(void);
|
void getfonts(void);
|
||||||
void *emalloc(int);
|
void *emalloc(int);
|
||||||
void nstrcpy(char *to, char *from, int len);
|
void nstrcpy(char *to, char *from, int len);
|
||||||
|
|
|
@ -143,11 +143,11 @@ urlget(Url *url, int body)
|
||||||
readstr(buf, buf, sizeof(buf));
|
readstr(buf, buf, sizeof(buf));
|
||||||
|
|
||||||
if(!cistrcmp(buf, "compress"))
|
if(!cistrcmp(buf, "compress"))
|
||||||
fd = pipeline("/bin/uncompress", fd);
|
fd = pipeline(fd, "exec uncompress");
|
||||||
else if(!cistrcmp(buf, "gzip"))
|
else if(!cistrcmp(buf, "gzip"))
|
||||||
fd = pipeline("/bin/gunzip", fd);
|
fd = pipeline(fd, "exec gunzip");
|
||||||
else if(!cistrcmp(buf, "bzip2"))
|
else if(!cistrcmp(buf, "bzip2"))
|
||||||
fd = pipeline("/bin/bunzip2", fd);
|
fd = pipeline(fd, "exec bunzip2");
|
||||||
|
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue