summaryrefslogtreecommitdiffstats
path: root/job.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@openbsd.org>2009-10-20 22:15:32 +0000
committerNicholas Marriott <nicm@openbsd.org>2009-10-20 22:15:32 +0000
commit6f2169037ecbadef09520e50ec4f2ef029f097a9 (patch)
treeef7dfaa7613983221899625b80b85acaf7b73a45 /job.c
parent480f5d31848dd79ed6d127a31899262cbe17626a (diff)
Sort out stdout before stdin/stderr in case the stdout side of the pipe got one
of their fds.
Diffstat (limited to 'job.c')
-rw-r--r--job.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/job.c b/job.c
index 6a824fa6..09ef6bc0 100644
--- a/job.c
+++ b/job.c
@@ -153,6 +153,12 @@ job_run(struct job *job)
sigreset();
/* XXX environ? */
+ close(out[1]);
+ if (dup2(out[0], STDOUT_FILENO) == -1)
+ fatal("dup2 failed");
+ if (out[0] != STDOUT_FILENO)
+ close(out[0]);
+
nullfd = open(_PATH_DEVNULL, O_RDONLY, 0);
if (nullfd < 0)
fatal("open failed");
@@ -163,12 +169,6 @@ 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 */