aboutsummaryrefslogtreecommitdiffhomepage
path: root/exec.cpp
diff options
context:
space:
mode:
authorGravatar Cheer Xiao <xiaqqaix@gmail.com>2013-02-05 12:29:44 +0800
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2013-02-11 22:05:48 -0800
commitdb551762121f7f7dd5f75725cfd6dda6c96ce5b9 (patch)
tree108febc4b261454f1989009f5cfdd74bea29c595 /exec.cpp
parent66a445f0432b0c882303c5a46433d945ec4086f3 (diff)
In exec(), only add and remove pipe_{read,write} when necessary
Diffstat (limited to 'exec.cpp')
-rw-r--r--exec.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/exec.cpp b/exec.cpp
index 11bf0814..9d9b0793 100644
--- a/exec.cpp
+++ b/exec.cpp
@@ -711,8 +711,8 @@ void exec(parser_t &parser, job_t *j)
/* The pipes the current process write to and read from.
Unfortunately these can't be just allocated on the stack, since
j->io wants shared_ptr. */
- shared_ptr<io_pipe_t> pipe_write(new io_pipe_t(p->pipe_write_fd, false));
- shared_ptr<io_pipe_t> pipe_read(new io_pipe_t(p->pipe_read_fd, true));
+ shared_ptr<io_pipe_t> pipe_write;
+ shared_ptr<io_pipe_t> pipe_read;
/* Record the current read in pipe_read */
pipe_read->pipe_fd[0] = pipe_current_read;
@@ -721,11 +721,13 @@ void exec(parser_t &parser, job_t *j)
if (p != j->first_process)
{
+ pipe_read.reset(new io_pipe_t(p->pipe_read_fd, true));
j->io.push_back(pipe_read);
}
if (p->next)
{
+ pipe_write.reset(new io_pipe_t(p->pipe_write_fd, false));
j->io.push_back(pipe_write);
}
@@ -1385,8 +1387,11 @@ void exec(parser_t &parser, job_t *j)
pipe_current_write = -1;
}
- j->io.remove(pipe_write);
- j->io.remove(pipe_read);
+ if (pipe_write.get())
+ j->io.remove(pipe_write);
+
+ if (pipe_read.get())
+ j->io.remove(pipe_read);
}
/* Clean up any file descriptors we left open */