static pid_t subprogram(ev_source *ev, const char *prog,
int outputfd) {
pid_t pid;
- int lfd;
/* If we're in the background then trap subprocess stdout/stderr */
- if(!isatty(2))
- lfd = logfd(ev, prog);
- else
- lfd = -1;
if(!(pid = xfork())) {
exitfn = _exit;
ev_signal_atfork(ev);
signal(SIGPIPE, SIG_DFL);
- if(lfd != -1) {
- xdup2(lfd, 1);
- xdup2(lfd, 2);
- xclose(lfd);
- }
if(outputfd != -1) {
xdup2(outputfd, 1);
xclose(outputfd);
(char *)0);
fatal(errno, "error invoking %s", prog);
}
- if(lfd != -1) xclose(lfd);
return pid;
}