aboutsummaryrefslogtreecommitdiffhomepage
path: root/proc.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2013-08-19 16:16:41 -0700
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2013-08-19 18:06:24 -0700
commit4899086b3c57ff2c36e62458ebb2986b95c2f631 (patch)
tree763aaf79dbfda63b8362416cf04e05325590955b /proc.cpp
parentf4f2847662a57c99a3ef0ae76adb304deccc5cac (diff)
Big fat refactoring of how redirections work. In fish 1.x and 2.0.0, the redirections for a process were flattened into a big list associated with the job, so there was no way to tell which redirections applied to each process. Each process therefore got all the redirections associated with the job. See https://github.com/fish-shell/fish-shell/issues/877 for how this could manifest.
With this change, jobs only track their block-level redirections. Process level redirections are correctly associated with the process, and at exec time we stitch them together (block, pipe, and process redirects). This fixes the weird issues where redirects bleed across pipelines (like #877), and also allows us to play with the order in which redirections are applied, since the final list is constructed right before it's needed. This lets us put pipes after block level redirections but before process level redirections, so that a 2>&1-type redirection gets picked up after the pipe, i.e. it should fix https://github.com/fish-shell/fish-shell/issues/110 This is a significant change. The tests all pass. Cross your fingers.
Diffstat (limited to 'proc.cpp')
-rw-r--r--proc.cpp25
1 files changed, 19 insertions, 6 deletions
diff --git a/proc.cpp b/proc.cpp
index b8231c38..1ca70099 100644
--- a/proc.cpp
+++ b/proc.cpp
@@ -537,10 +537,10 @@ process_t::~process_t()
delete this->next;
}
-job_t::job_t(job_id_t jobid) :
+job_t::job_t(job_id_t jobid, const io_chain_t &bio) :
command_str(),
command_narrow(),
- io(),
+ block_io(bio),
first_process(NULL),
pgid(0),
tmodes(),
@@ -556,6 +556,17 @@ job_t::~job_t()
release_job_id(job_id);
}
+/* Return all the IO redirections. Start with the block IO, then walk over the processes */
+io_chain_t job_t::all_io_redirections() const
+{
+ io_chain_t result = this->block_io;
+ for (process_t *p = this->first_process; p != NULL; p = p->next)
+ {
+ result.append(p->io_chain());
+ }
+ return result;
+}
+
/* This is called from a signal handler */
void job_handle_signal(int signal, siginfo_t *info, void *con)
{
@@ -874,9 +885,10 @@ static int select_try(job_t *j)
FD_ZERO(&fds);
- for (size_t idx = 0; idx < j->io_chain().size(); idx++)
+ const io_chain_t chain = j->all_io_redirections();
+ for (size_t idx = 0; idx < chain.size(); idx++)
{
- const io_data_t *io = j->io_chain().at(idx).get();
+ const io_data_t *io = chain.at(idx).get();
if (io->io_mode == IO_BUFFER)
{
CAST_INIT(const io_pipe_t *, io_pipe, io);
@@ -915,9 +927,10 @@ static void read_try(job_t *j)
/*
Find the last buffer, which is the one we want to read from
*/
- for (size_t idx = 0; idx < j->io_chain().size(); idx++)
+ const io_chain_t chain = j->all_io_redirections();
+ for (size_t idx = 0; idx < chain.size(); idx++)
{
- io_data_t *d = j->io_chain().at(idx).get();
+ io_data_t *d = chain.at(idx).get();
if (d->io_mode == IO_BUFFER)
{
buff = static_cast<io_buffer_t *>(d);