src/exec: fix assertion on failed exec redirection

Minimal reproducer: `fish -c "exec cat<x"`
This commit is contained in:
Mrmaxmeier 2019-02-11 17:10:42 +01:00 committed by ridiculousfish
parent b247c8d9ad
commit 6e9250425a
5 changed files with 18 additions and 1 deletions

View File

@ -970,7 +970,11 @@ bool exec_job(parser_t &parser, shared_ptr<job_t> j) {
if (j->processes.front()->type == INTERNAL_EXEC) {
internal_exec(parser.vars(), j.get(), all_ios);
DIE("this should be unreachable");
// internal_exec only returns if it failed to set up redirections.
// In case of an successful exec, this code is not reached.
bool status = j->get_flag(job_flag_t::NEGATE) ? 0 : 1;
proc_set_last_status(status);
return false;
}
// This loop loops over every process_t in the job, starting it as appropriate. This turns out

4
tests/test_exec_fail.err Normal file
View File

@ -0,0 +1,4 @@
<W> fish: An error occurred while redirecting file 'nosuchfile'
open: No such file or directory
<W> fish: An error occurred while redirecting file 'nosuchfile'
open: No such file or directory

6
tests/test_exec_fail.in Normal file
View File

@ -0,0 +1,6 @@
exec cat < nosuchfile
echo "failed: $status"
not exec cat < nosuchfile
echo "neg failed: $status"
exec cat < /dev/null
echo "not reached"

2
tests/test_exec_fail.out Normal file
View File

@ -0,0 +1,2 @@
failed: 1
neg failed: 0

View File

@ -0,0 +1 @@
0