summaryrefslogtreecommitdiffstats
path: root/job.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@openbsd.org>2009-10-21 07:24:23 +0000
committerNicholas Marriott <nicm@openbsd.org>2009-10-21 07:24:23 +0000
commit7825871d6a04494c704521abb6fc4240216382ca (patch)
tree997a60cdcbaa2c0960c22b2ff3ae5309bee97544 /job.c
parent9afb0d739e96a8b5a8ac4a2ae19803443135d0e2 (diff)
Getting the read and write ends of the pipe the right way round is usually
recommended. DOH.
Diffstat (limited to 'job.c')
-rw-r--r--job.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/job.c b/job.c
index 09ef6bc0..dea37784 100644
--- a/job.c
+++ b/job.c
@@ -153,13 +153,13 @@ job_run(struct job *job)
sigreset();
/* XXX environ? */
- close(out[1]);
- if (dup2(out[0], STDOUT_FILENO) == -1)
+ if (dup2(out[1], STDOUT_FILENO) == -1)
fatal("dup2 failed");
- if (out[0] != STDOUT_FILENO)
- close(out[0]);
+ if (out[1] != STDOUT_FILENO)
+ close(out[1]);
+ close(out[0]);
- nullfd = open(_PATH_DEVNULL, O_RDONLY, 0);
+ nullfd = open(_PATH_DEVNULL, O_RDWR, 0);
if (nullfd < 0)
fatal("open failed");
if (dup2(nullfd, STDIN_FILENO) == -1)
@@ -172,9 +172,9 @@ job_run(struct job *job)
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)