From b01d09d704893b59aa87308d3408c084017c46dd Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Wed, 2 Apr 2014 00:32:08 -0700 Subject: [PATCH] Set the job property of block_t before expanding arguments associated with the job, fixing psub. Fixes #1394 --- parse_execution.cpp | 6 +++++- tests/test9.in | 5 +++++ tests/test9.out | 3 +++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/parse_execution.cpp b/parse_execution.cpp index 78baed79f..d5c63aba9 100644 --- a/parse_execution.cpp +++ b/parse_execution.cpp @@ -1383,6 +1383,9 @@ parse_execution_result_t parse_execution_context_t::run_1_job(const parse_node_t || is_event \ || (!get_is_interactive())); + /* Tell the current block what its job is. This has to happen before we populate it (#1394) */ + parser->current_block()->job = j; + /* Populate the job. This may fail for reasons like command_not_found. If this fails, an error will have been printed */ parse_execution_result_t pop_result = this->populate_job_from_job_node(j, job_node, associated_block); @@ -1390,6 +1393,8 @@ parse_execution_result_t parse_execution_context_t::run_1_job(const parse_node_t bool populated_job = (pop_result == parse_execution_success); if (! populated_job || this->should_cancel_execution(associated_block)) { + assert(parser->current_block()->job == j); + parser->current_block()->job = NULL; delete j; j = NULL; populated_job = false; @@ -1406,7 +1411,6 @@ parse_execution_result_t parse_execution_context_t::run_1_job(const parse_node_t { /* Success. Give the job to the parser - it will clean it up. */ parser->job_add(j); - parser->current_block()->job = j; /* Check to see if this contained any external commands */ bool job_contained_external_command = false; diff --git a/tests/test9.in b/tests/test9.in index a3a48151a..e40bc74ec 100644 --- a/tests/test9.in +++ b/tests/test9.in @@ -84,4 +84,9 @@ eval 'status -n status -n status -n' +# Test psub +cat (echo foo | psub) +cat (echo bar | psub) +cat (echo baz | psub) + false diff --git a/tests/test9.out b/tests/test9.out index d42618630..7580b1d85 100644 --- a/tests/test9.out +++ b/tests/test9.out @@ -13,3 +13,6 @@ Testing for loop 1 2 3 +foo +bar +baz