mirror of
/repos/baseimage-docker.git
synced 2025-12-31 08:11:29 +01:00
Correctly pass child process' exit status to sys.exit(). Closes GH-45
This commit is contained in:
parent
5ae32384d5
commit
8f9eefa1f6
@ -143,9 +143,9 @@ def run_command_killable(*argv):
|
|||||||
raise
|
raise
|
||||||
if status != 0:
|
if status != 0:
|
||||||
if status is None:
|
if status is None:
|
||||||
error("%s exited with unknown exit code\n" % filename)
|
error("%s exited with unknown status\n" % filename)
|
||||||
else:
|
else:
|
||||||
error("%s failed with exit code %d\n" % (filename, status))
|
error("%s failed with status %d\n" % (filename, os.WEXITSTATUS(status)))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def run_command_killable_and_import_envvars(*argv):
|
def run_command_killable_and_import_envvars(*argv):
|
||||||
@ -239,31 +239,34 @@ def main(args):
|
|||||||
if not args.skip_runit:
|
if not args.skip_runit:
|
||||||
runit_pid = start_runit()
|
runit_pid = start_runit()
|
||||||
try:
|
try:
|
||||||
|
exit_status = None
|
||||||
if len(args.main_command) == 0:
|
if len(args.main_command) == 0:
|
||||||
runit_exited, exit_code = wait_for_runit_or_interrupt(runit_pid)
|
runit_exited, exit_code = wait_for_runit_or_interrupt(runit_pid)
|
||||||
if runit_exited:
|
if runit_exited:
|
||||||
if exit_code is None:
|
if exit_code is None:
|
||||||
info("Runit exited with unknown exit code")
|
info("Runit exited with unknown status")
|
||||||
exit_code = 1
|
exit_status = 1
|
||||||
else:
|
else:
|
||||||
info("Runit exited with code %d" % exit_code)
|
exit_status = os.WEXITSTATUS(exit_code)
|
||||||
|
info("Runit exited with status %d" % exit_status)
|
||||||
else:
|
else:
|
||||||
info("Running %s..." % " ".join(args.main_command))
|
info("Running %s..." % " ".join(args.main_command))
|
||||||
pid = os.spawnvp(os.P_NOWAIT, args.main_command[0], args.main_command)
|
pid = os.spawnvp(os.P_NOWAIT, args.main_command[0], args.main_command)
|
||||||
try:
|
try:
|
||||||
exit_code = waitpid_reap_other_children(pid)
|
exit_code = waitpid_reap_other_children(pid)
|
||||||
if exit_code is None:
|
if exit_code is None:
|
||||||
info("%s exited with unknown exit code." % args.main_command[0])
|
info("%s exited with unknown status." % args.main_command[0])
|
||||||
exit_code = 1
|
exit_status = 1
|
||||||
else:
|
else:
|
||||||
info("%s exited with exit code %d." % (args.main_command[0], exit_code))
|
exit_status = os.WEXITSTATUS(exit_code)
|
||||||
|
info("%s exited with status %d." % (args.main_command[0], exit_status))
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
stop_child_process(args.main_command[0], pid)
|
stop_child_process(args.main_command[0], pid)
|
||||||
except BaseException as s:
|
except BaseException as s:
|
||||||
warn("An error occurred. Aborting.")
|
warn("An error occurred. Aborting.")
|
||||||
stop_child_process(args.main_command[0], pid)
|
stop_child_process(args.main_command[0], pid)
|
||||||
raise
|
raise
|
||||||
sys.exit(exit_code)
|
sys.exit(exit_status)
|
||||||
finally:
|
finally:
|
||||||
if not args.skip_runit:
|
if not args.skip_runit:
|
||||||
shutdown_runit_services()
|
shutdown_runit_services()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user