diff options
author | Geoff Nixon <geoff@geoff.codes> | 2015-01-20 23:44:49 -0800 |
---|---|---|
committer | ridiculousfish <corydoras@ridiculousfish.com> | 2015-03-11 20:32:16 +0800 |
commit | b9bd0166b6952d715d82e045239465adfa0877f2 (patch) | |
tree | 7624546be008783f6aad9571298fa26eb4e2fc57 /parse_execution.cpp | |
parent | 1116929d2f20f299a28c1211f48805dc4f495975 (diff) |
Fix return value of if/else statements to match POSIX. Hopefully should close #1443, and reverses some of #1061 / e632d39b.
Diffstat (limited to 'parse_execution.cpp')
-rw-r--r-- | parse_execution.cpp | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/parse_execution.cpp b/parse_execution.cpp index c75c135f..2b43ccc4 100644 --- a/parse_execution.cpp +++ b/parse_execution.cpp @@ -295,8 +295,9 @@ parse_execution_result_t parse_execution_context_t::run_if_statement(const parse } else if (else_clause->child_count == 0) { - /* 'if' condition failed, no else clause, we're done */ + /* 'if' condition failed, no else clause, return 0, we're done. */ job_list_to_execute = NULL; + proc_set_last_status(STATUS_BUILTIN_OK); break; } else @@ -325,8 +326,12 @@ parse_execution_result_t parse_execution_context_t::run_if_statement(const parse { run_job_list(*job_list_to_execute, ib); } + else + { /* No job list means no sucessful conditions, so return 0 (#1443). */ + proc_set_last_status(STATUS_BUILTIN_OK); + } - /* It's possible there's a last-minute cancellation, in which case we should not stomp the exit status (#1297) */ + /* It's possible there's a last-minute cancellation (#1297). */ if (should_cancel_execution(ib)) { result = parse_execution_cancelled; @@ -335,12 +340,7 @@ parse_execution_result_t parse_execution_context_t::run_if_statement(const parse /* Done */ parser->pop_block(ib); - /* Issue 1061: If we executed, then always report success, instead of letting the exit status of the last command linger */ - if (result == parse_execution_success) - { - proc_set_last_status(STATUS_BUILTIN_OK); - } - + /* Otherwise, take the exit status of the job list. Reversal of #1061. */ return result; } |