Skip to content

Commit e5a329a

Browse files
committed
run-command: report exec failure
In 321fd82 ("run-command: mark path lookup errors with ENOENT", 2018-10-24), we rewrote the logic to execute a command by looking in the directories on $PATH; as a side effect, a request to run a command that is not found on $PATH is noticed even before a child process is forked to execute it. We however stopped to report an exec failure in such a case by mistake. Add a logic to report the error unless silent-exec-failure is requested, to match the original code. Reported-by: John Passaro <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f67b980 commit e5a329a

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

run-command.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,8 @@ int start_command(struct child_process *cmd)
728728
if (prepare_cmd(&argv, cmd) < 0) {
729729
failed_errno = errno;
730730
cmd->pid = -1;
731+
if (!cmd->silent_exec_failure)
732+
error_errno("cannot run %s", cmd->argv[0]);
731733
goto end_of_spawn;
732734
}
733735

t/t0061-run-command.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ EOF
1414
>empty
1515

1616
test_expect_success 'start_command reports ENOENT (slash)' '
17-
test-tool run-command start-command-ENOENT ./does-not-exist
17+
test-tool run-command start-command-ENOENT ./does-not-exist 2>err &&
18+
test_i18ngrep "\./does-not-exist" err
1819
'
1920

2021
test_expect_success 'start_command reports ENOENT (no slash)' '
21-
test-tool run-command start-command-ENOENT does-not-exist
22+
test-tool run-command start-command-ENOENT does-not-exist 2>err &&
23+
test_i18ngrep "does-not-exist" err
2224
'
2325

2426
test_expect_success 'run_command can run a command' '
@@ -34,7 +36,8 @@ test_expect_success 'run_command is restricted to PATH' '
3436
write_script should-not-run <<-\EOF &&
3537
echo yikes
3638
EOF
37-
test_must_fail test-tool run-command run-command should-not-run
39+
test_must_fail test-tool run-command run-command should-not-run 2>err &&
40+
test_i18ngrep "should-not-run" err
3841
'
3942

4043
test_expect_success !MINGW 'run_command can run a script without a #! line' '

0 commit comments

Comments
 (0)