From 5fbdf6c3fcc7905a9b3cd428514c2fa089432278 Mon Sep 17 00:00:00 2001 From: Julian Friedman Date: Tue, 16 Feb 2016 09:59:16 +0000 Subject: [PATCH] Register signal handlers earlier to avoid zombies newSignalHandler needs to be called before the process is started, otherwise when the process exits quickly the SIGCHLD is recieved (and ignored) before the handler is set up. When this happens the reaper never runs, the process becomes a zombie, and the exit code isn't returned to the user. Signed-off-by: Julian Friedman --- restore.go | 4 ++-- utils.go | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/restore.go b/restore.go index 067c13d3..51ca88b9 100644 --- a/restore.go +++ b/restore.go @@ -134,6 +134,8 @@ func restoreContainer(context *cli.Context, spec *specs.LinuxSpec, config *confi if err != nil { return -1, err } + handler := newSignalHandler(tty) + defer handler.Close() if err := container.Restore(process, options); err != nil { tty.Close() return -1, err @@ -149,8 +151,6 @@ func restoreContainer(context *cli.Context, spec *specs.LinuxSpec, config *confi if detach { return 0, nil } - handler := newSignalHandler(tty) - defer handler.Close() return handler.forward(process) } diff --git a/utils.go b/utils.go index fe52b1bb..ef6fbba3 100644 --- a/utils.go +++ b/utils.go @@ -307,6 +307,9 @@ func runProcess(container libcontainer.Container, config *specs.Process, listenF return -1, err } + handler := newSignalHandler(tty) + defer handler.Close() + if err := container.Start(process); err != nil { tty.Close() return -1, err @@ -323,8 +326,6 @@ func runProcess(container libcontainer.Container, config *specs.Process, listenF if detach { return 0, nil } - handler := newSignalHandler(tty) - defer handler.Close() return handler.forward(process) }