From 2a94a930e1436f8326240d3f4c6c8119a928c9a6 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Mon, 3 Aug 2015 16:27:56 -0700 Subject: [PATCH] Use signal handler for restore There was previously a memory issue in the signal handler that showed up when using restore. This has been fixed, therefore, restore can use the signal handler. Signed-off-by: Michael Crosby --- restore.go | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/restore.go b/restore.go index 900a5257..fc86e3f5 100644 --- a/restore.go +++ b/restore.go @@ -4,14 +4,11 @@ package main import ( "os" - "os/signal" - "syscall" "github.com/Sirupsen/logrus" "github.com/codegangsta/cli" "github.com/opencontainers/runc/libcontainer" "github.com/opencontainers/runc/libcontainer/configs" - "github.com/opencontainers/runc/libcontainer/utils" "github.com/opencontainers/specs" ) @@ -89,16 +86,12 @@ func restoreContainer(context *cli.Context, spec *specs.LinuxSpec, config *confi if err != nil { return -1, err } - defer tty.Close() - go handleSignals(process, tty) + handler := newSignalHandler(tty) + defer handler.Close() if err := container.Restore(process, options); err != nil { return -1, err } - status, err := process.Wait() - if err != nil { - return -1, err - } - return utils.ExitStatus(status.Sys().(syscall.WaitStatus)), nil + return handler.forward(process) } func criuOptions(context *cli.Context) *libcontainer.CriuOpts { @@ -116,19 +109,3 @@ func criuOptions(context *cli.Context) *libcontainer.CriuOpts { FileLocks: context.Bool("file-locks"), } } - -// we have to use this type of signal handler because there is a memory leak if we -// wait and reap with SIGCHLD. -func handleSignals(process *libcontainer.Process, tty *tty) { - sigc := make(chan os.Signal, 10) - signal.Notify(sigc) - tty.resize() - for sig := range sigc { - switch sig { - case syscall.SIGWINCH: - tty.resize() - default: - process.Signal(sig) - } - } -}