diff --git a/job.c b/job.c index 5ec1ccac..00c73d91 100644 --- a/job.c +++ b/job.c @@ -1,4 +1,4 @@ -/* $Id: job.c,v 1.6 2009-10-12 00:25:25 tcunha Exp $ */ +/* $Id: job.c,v 1.7 2009-10-21 07:37:11 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -152,7 +152,13 @@ job_run(struct job *job) sigreset(); /* XXX environ? */ - nullfd = open(_PATH_DEVNULL, O_RDONLY, 0); + if (dup2(out[1], STDOUT_FILENO) == -1) + fatal("dup2 failed"); + if (out[1] != STDOUT_FILENO) + close(out[1]); + close(out[0]); + + nullfd = open(_PATH_DEVNULL, O_RDWR, 0); if (nullfd < 0) fatal("open failed"); if (dup2(nullfd, STDIN_FILENO) == -1) @@ -162,18 +168,12 @@ job_run(struct job *job) if (nullfd != STDIN_FILENO && nullfd != STDERR_FILENO) close(nullfd); - close(out[1]); - if (dup2(out[0], STDOUT_FILENO) == -1) - fatal("dup2 failed"); - if (out[0] != STDOUT_FILENO) - close(out[0]); - execl(_PATH_BSHELL, "sh", "-c", job->cmd, (char *) NULL); fatal("execl failed"); default: /* parent */ - close(out[0]); + close(out[1]); - job->fd = out[1]; + job->fd = out[0]; if ((mode = fcntl(job->fd, F_GETFL)) == -1) fatal("fcntl failed"); if (fcntl(job->fd, F_SETFL, mode|O_NONBLOCK) == -1)