phusion / baseimage-docker

A minimal Ubuntu base image modified for Docker-friendliness
http://phusion.github.io/baseimage-docker/
MIT License
8.96k stars 1.09k forks source link

my_init doesn't preserve non-zero exit status #45

Closed harto closed 10 years ago

harto commented 10 years ago

Unless I'm misunderstanding something, the final line of this output should read 42:

$ docker run --rm phusion/baseimage:0.9.9 /sbin/my_init --skip-runit -- bash -c 'exit 42'
*** Running /etc/my_init.d/00_regen_ssh_host_keys.sh...
No SSH host key available. Generating one...
Creating SSH2 RSA key; this may take some time ...
Creating SSH2 DSA key; this may take some time ...
Creating SSH2 ECDSA key; this may take some time ...
*** Running /etc/rc.local...
*** Running bash -c exit 42...
*** bash exited with exit code 10752.
*** Killing all processes...
$ echo $?
0
harto commented 10 years ago

The abnormally large exit code value (10752) is ignored by sys.exit:

$ python -c 'import sys; sys.exit(10752)'; echo $?
0

Probably because, according to http://docs.python.org/2/library/sys.html#sys.exit:

Most systems require [the exit code] to be in the range 0-127, and produce undefined results otherwise.

FooBarWidget commented 10 years ago

Can you test this?

pda commented 10 years ago

Looks good to me:

# Previous version:
root@e63c58ccd0ef:/# /sbin/my_init --skip-runit --quiet -- bash -c 'exit 42'; echo $?
0
# Current master:
root@e63c58ccd0ef:/# /baseimage-docker/image/my_init --skip-runit --quiet -- bash -c 'exit 42'; echo $?
42
harto commented 10 years ago

Awesome, thanks! :-)