Fix exit codes when dying on a signal

Test the process WaitStatus for a signal, and return an exit code of 128
+ signal which killed the process. Fixes docker/docker#9979.

Signed-off-by: Arnaud Porterie <arnaud.porterie@docker.com>
This commit is contained in:
Arnaud Porterie 2015-01-12 16:18:21 -08:00
parent 9377591781
commit fec4c5ab0a
1 changed files with 10 additions and 1 deletions

View File

@ -17,6 +17,10 @@ import (
"github.com/docker/libcontainer/system"
)
const (
EXIT_SIGNAL_OFFSET = 128
)
// TODO(vishh): This is part of the libcontainer API and it does much more than just namespaces related work.
// Move this to libcontainer package.
// Exec performs setup outside of a namespace so that a container can be
@ -113,7 +117,12 @@ func Exec(container *libcontainer.Config, stdin io.Reader, stdout, stderr io.Wri
if !container.Namespaces.Contains(libcontainer.NEWPID) {
killAllPids(container)
}
return command.ProcessState.Sys().(syscall.WaitStatus).ExitStatus(), nil
waitStatus := command.ProcessState.Sys().(syscall.WaitStatus)
if waitStatus.Signaled() {
return EXIT_SIGNAL_OFFSET + int(waitStatus.Signal()), nil
}
return waitStatus.ExitStatus(), nil
}
// killAllPids itterates over all of the container's processes