Skip to content

Commit 3970fc5

Browse files
committed
Merge branch 'jn/run-command-error-failure'
* jn/run-command-error-failure: run-command: handle short writes and EINTR in die_child tests: check error message from run_command
2 parents 606ee4b + a111eb7 commit 3970fc5

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

run-command.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,24 @@ static int child_notifier = -1;
6767

6868
static void notify_parent(void)
6969
{
70-
ssize_t unused;
71-
unused = write(child_notifier, "", 1);
70+
/*
71+
* execvp failed. If possible, we'd like to let start_command
72+
* know, so failures like ENOENT can be handled right away; but
73+
* otherwise, finish_command will still report the error.
74+
*/
75+
xwrite(child_notifier, "", 1);
7276
}
7377

7478
static NORETURN void die_child(const char *err, va_list params)
7579
{
7680
char msg[4096];
77-
ssize_t unused;
7881
int len = vsnprintf(msg, sizeof(msg), err, params);
7982
if (len > sizeof(msg))
8083
len = sizeof(msg);
8184

82-
unused = write(child_err, "fatal: ", 7);
83-
unused = write(child_err, msg, len);
84-
unused = write(child_err, "\n", 1);
85+
write_in_full(child_err, "fatal: ", 7);
86+
write_in_full(child_err, msg, len);
87+
write_in_full(child_err, "\n", 1);
8588
exit(128);
8689
}
8790
#endif

t/t0061-run-command.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,31 @@ test_description='Test run command'
77

88
. ./test-lib.sh
99

10+
cat >hello-script <<-EOF
11+
#!$SHELL_PATH
12+
cat hello-script
13+
EOF
14+
>empty
15+
1016
test_expect_success 'start_command reports ENOENT' '
1117
test-run-command start-command-ENOENT ./does-not-exist
1218
'
1319

20+
test_expect_success 'run_command can run a command' '
21+
cat hello-script >hello.sh &&
22+
chmod +x hello.sh &&
23+
test-run-command run-command ./hello.sh >actual 2>err &&
24+
25+
test_cmp hello-script actual &&
26+
test_cmp empty err
27+
'
28+
29+
test_expect_success POSIXPERM 'run_command reports EACCES' '
30+
cat hello-script >hello.sh &&
31+
chmod -x hello.sh &&
32+
test_must_fail test-run-command run-command ./hello.sh 2>err &&
33+
34+
grep "fatal: cannot exec.*hello.sh" err
35+
'
36+
1437
test_done

test-run-command.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ int main(int argc, char **argv)
2929
fprintf(stderr, "FAIL %s\n", argv[1]);
3030
return 1;
3131
}
32+
if (!strcmp(argv[1], "run-command"))
33+
exit(run_command(&proc));
3234

3335
fprintf(stderr, "check usage\n");
3436
return 1;

0 commit comments

Comments
 (0)