diff options
author | Cheer Xiao <xiaqqaix@gmail.com> | 2013-02-04 20:07:16 +0800 |
---|---|---|
committer | ridiculousfish <corydoras@ridiculousfish.com> | 2013-02-11 22:05:47 -0800 |
commit | 3f9706a7f350fcac43fc389b0b52b3601269e2e9 (patch) | |
tree | 7bc25f1a6bbbdf66ec56aaf5bc2c321dda45f879 /exec.cpp | |
parent | 41fc3bcb748efc20e36160f5c361882c854f4baf (diff) |
Make io_data_t::fd const
In exec(), pipe_{write,read} no longer get reused.
Diffstat (limited to 'exec.cpp')
-rw-r--r-- | exec.cpp | 53 |
1 files changed, 21 insertions, 32 deletions
@@ -622,15 +622,6 @@ void exec(parser_t &parser, job_t *j) } - // This is a pipe that the "current" process in our loop below reads from - // Only pipe_read->pipe_fd[0] is used - shared_ptr<io_pipe_t> pipe_read(new io_pipe_t(0, true)); - - // This is the pipe that the "current" process in our loop below writes to - shared_ptr<io_pipe_t> pipe_write(new io_pipe_t(1, false)); - - j->io.push_back(pipe_write); - signal_block(); /* @@ -714,16 +705,29 @@ void exec(parser_t &parser, job_t *j) pipe_current_read = pipe_next_read; pipe_next_read = -1; - /* Record the current read in pipe_read */ - pipe_read->pipe_fd[0] = pipe_current_read; - /* See if we need a pipe */ const bool pipes_to_next_command = (p->next != NULL); - pipe_write->fd = p->pipe_write_fd; - pipe_read->fd = p->pipe_read_fd; + /* 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)); + + /* Record the current read in pipe_read */ + pipe_read->pipe_fd[0] = pipe_current_read; + // debug( 0, L"Pipe created from fd %d to fd %d", pipe_write->fd, pipe_read->fd ); + if (p != j->first_process) + { + j->io.push_back(pipe_read); + } + + if (p->next) + { + j->io.push_back(pipe_write); + } /* This call is used so the global environment variable array @@ -742,12 +746,6 @@ void exec(parser_t &parser, job_t *j) Set up fd:s that will be used in the pipe */ - if (p == j->first_process->next) - { - /* We are the first process that could possibly read from a pipe (aka the second process), so add the pipe read redirection */ - j->io.push_back(pipe_read); - } - if (pipes_to_next_command) { // debug( 1, L"%ls|%ls" , p->argv[0], p->next->argv[0]); @@ -772,16 +770,6 @@ void exec(parser_t &parser, job_t *j) assert(pipe_next_read == -1); pipe_next_read = local_pipe[0]; } - else - { - /* - This is the last element of the pipeline. - Remove the io redirection for pipe output. - */ - io_chain_t::iterator where = std::find(j->io.begin(), j->io.end(), pipe_write); - if (where != j->io.end()) - j->io.erase(where); - } switch (p->type) { @@ -1396,6 +1384,9 @@ void exec(parser_t &parser, job_t *j) exec_close(pipe_current_write); pipe_current_write = -1; } + + j->io.remove(pipe_write); + j->io.remove(pipe_read); } /* Clean up any file descriptors we left open */ @@ -1416,8 +1407,6 @@ void exec(parser_t &parser, job_t *j) debug(3, L"Job is constructed"); - io_remove(j->io, pipe_read); - job_set_flag(j, JOB_CONSTRUCTED, 1); if (!job_get_flag(j, JOB_FOREGROUND)) |