diff options
author | Nicholas Marriott <nicholas.marriott@gmail.com> | 2009-10-21 07:37:11 +0000 |
---|---|---|
committer | Nicholas Marriott <nicholas.marriott@gmail.com> | 2009-10-21 07:37:11 +0000 |
commit | 4afecbe400ef8452edec957795b9c69800eee411 (patch) | |
tree | fcbc7f5bfb80c0bc1657fb7a38289c3db2c29120 | |
parent | bb625a76d945f0264a4c48fad331e63e0d50dff7 (diff) | |
download | rtmux-4afecbe400ef8452edec957795b9c69800eee411.tar.gz rtmux-4afecbe400ef8452edec957795b9c69800eee411.tar.bz2 rtmux-4afecbe400ef8452edec957795b9c69800eee411.zip |
Getting the read and write ends of the pipe the right way round is usually
recommended. DOH.
-rw-r--r-- | job.c | 20 |
1 files changed, 10 insertions, 10 deletions
@@ -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 <nicm@users.sourceforge.net> @@ -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) |