{
int pid, pid_show, n;
int mailpipe[2];
- char *errstr;
if (filter == NULL)
return;
rewind(in);
lseek(fileno(in), (off_t) 0, SEEK_SET);
- if (pipe(mailpipe) == -1) {
- adios(EX_OSERR, "pipe", "can't create pipe");
- }
-
- switch (pid_show = fork()) {
- case NOTOK:
- adios(EX_OSERR, "fork", "unable to");
-
- case OK:
- dup2(fileno(in), fileno(stdin));
- dup2(mailpipe[1], fileno(stdout));
- for (n=3; n<OPEN_MAX; n++) {
- close(n);
- }
-
- execlp("show", "show", "-file", "-", NULL);
-
- adios(EX_OSERR, "exec", "unable to");
- }
-
switch (pid = fork()) {
case NOTOK:
adios(EX_OSERR, "fork", "unable to");
case OK:
- dup2(mailpipe[0], fileno(stdin));
- dup2(fileno(out), fileno(stdout));
- for (n=3; n<OPEN_MAX; n++) {
- close(n);
+ if (pipe(mailpipe) == -1) {
+ adios(EX_OSERR, "pipe", "can't create pipe");
}
- execlp("mhl", "mhl", "-form", filter, NULL);
- errstr = strerror(errno);
- write(2, "unable to exec mhl: ", 20);
- write(2, errstr, strlen(errstr));
- write(2, "\n", 1);
- _exit(EX_OSERR);
+ switch (pid_show = fork()) {
+ case NOTOK:
+ adios(EX_OSERR, "fork", "unable to");
+ case OK:
+ dup2(fileno(in), STDIN_FILENO);
+ dup2(mailpipe[1], STDOUT_FILENO);
+ close(fileno(in));
+ close(fileno(out));
+ close(mailpipe[0]);
+ close(mailpipe[1]);
+ for (n=3; n<OPEN_MAX; n++) {
+ close(n);
+ }
+ execlp("show", "show", "-file", "-", NULL);
+ adios(EX_OSERR, "exec", "unable to");
+ break;
+ default:
+ dup2(mailpipe[0], STDIN_FILENO);
+ dup2(fileno(out), STDOUT_FILENO);
+ close(fileno(in));
+ close(fileno(out));
+ close(mailpipe[0]);
+ close(mailpipe[1]);
+ for (n=3; n<OPEN_MAX; n++) {
+ close(n);
+ }
+ execlp("mhl", "mhl", "-form", filter, NULL);
+ adios(EX_OSERR, "exec", "unable to");
+ break;
+ }
default:
- if (pidXwait(-1, "show | mhl"))
+ if (pidXwait(pid, "mhl")) {
exit(EX_SOFTWARE);
+ }
fseek(out, 0L, SEEK_END);
break;
}
-
- close(mailpipe[0]);
- close(mailpipe[1]);
}