Merge pull request #33 from chriskuehl/fix-exec-failures
Exit nonzero if exec fails
This commit is contained in:
commit
ebafb14130
3 changed files with 27 additions and 0 deletions
|
@ -128,6 +128,15 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
|
||||
execvp(argv[1], &argv[1]);
|
||||
|
||||
// if this point is reached, exec failed, so we should exit nonzero
|
||||
fprintf(
|
||||
stderr,
|
||||
"dumb-init: %s: %s\n",
|
||||
argv[1],
|
||||
strerror(errno)
|
||||
);
|
||||
exit(2);
|
||||
} else {
|
||||
pid_t killed_pid;
|
||||
int exit_status, status;
|
||||
|
|
|
@ -123,3 +123,14 @@ def test_processes_dont_receive_term_on_exit_if_no_setsid(
|
|||
assert child_stdout.readline() == str(signum).encode('ascii') + b'\n'
|
||||
|
||||
os.kill(child_pid, signal.SIGKILL)
|
||||
|
||||
|
||||
def test_fails_nonzero_with_bad_exec(both_debug_modes, both_setsid_modes):
|
||||
"""If dumb-init can't exec as requested, it should exit nonzero."""
|
||||
proc = Popen(('dumb-init', '/doesnotexist'), stderr=PIPE)
|
||||
proc.wait()
|
||||
assert proc.returncode != 0
|
||||
assert (
|
||||
b'dumb-init: /doesnotexist: No such file or directory\n'
|
||||
in proc.stderr
|
||||
)
|
||||
|
|
7
tox.ini
7
tox.ini
|
@ -9,3 +9,10 @@ commands =
|
|||
|
||||
[testenv:pre-commit]
|
||||
commands = pre-commit {posargs}
|
||||
|
||||
[flake8]
|
||||
max-line-length = 119
|
||||
|
||||
[pep8]
|
||||
# autopep8 will rewrite lines to be shorter, even though we raised the length
|
||||
ignore = E501
|
||||
|
|
Loading…
Reference in a new issue