diff --git a/dumb-init.c b/dumb-init.c index febd4b8..ed9de6b 100644 --- a/dumb-init.c +++ b/dumb-init.c @@ -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; diff --git a/tests/child_processes_test.py b/tests/child_processes_test.py index 5e2d686..315795a 100644 --- a/tests/child_processes_test.py +++ b/tests/child_processes_test.py @@ -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 + ) diff --git a/tox.ini b/tox.ini index 8f94ee6..26a65b3 100644 --- a/tox.ini +++ b/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