1
0
mirror of https://github.com/tmux/tmux.git synced 2025-04-10 19:18:48 +00:00

Getting the read and write ends of the pipe the right way round is usually

recommended. DOH.
This commit is contained in:
Nicholas Marriott 2009-10-21 07:24:23 +00:00
parent 9afb0d739e
commit 7825871d6a

14
job.c
View File

@ -153,13 +153,13 @@ job_run(struct job *job)
sigreset(); sigreset();
/* XXX environ? */ /* XXX environ? */
close(out[1]); if (dup2(out[1], STDOUT_FILENO) == -1)
if (dup2(out[0], STDOUT_FILENO) == -1)
fatal("dup2 failed"); fatal("dup2 failed");
if (out[0] != STDOUT_FILENO) if (out[1] != STDOUT_FILENO)
close(out[0]); close(out[1]);
close(out[0]);
nullfd = open(_PATH_DEVNULL, O_RDONLY, 0); nullfd = open(_PATH_DEVNULL, O_RDWR, 0);
if (nullfd < 0) if (nullfd < 0)
fatal("open failed"); fatal("open failed");
if (dup2(nullfd, STDIN_FILENO) == -1) if (dup2(nullfd, STDIN_FILENO) == -1)
@ -172,9 +172,9 @@ job_run(struct job *job)
execl(_PATH_BSHELL, "sh", "-c", job->cmd, (char *) NULL); execl(_PATH_BSHELL, "sh", "-c", job->cmd, (char *) NULL);
fatal("execl failed"); fatal("execl failed");
default: /* parent */ default: /* parent */
close(out[0]); close(out[1]);
job->fd = out[1]; job->fd = out[0];
if ((mode = fcntl(job->fd, F_GETFL)) == -1) if ((mode = fcntl(job->fd, F_GETFL)) == -1)
fatal("fcntl failed"); fatal("fcntl failed");
if (fcntl(job->fd, F_SETFL, mode|O_NONBLOCK) == -1) if (fcntl(job->fd, F_SETFL, mode|O_NONBLOCK) == -1)