Merge pull request #174 from crosbymichael/restore-signal-handler

Use signal handler for restore
This commit is contained in:
Alexander Morozov 2015-08-04 11:26:54 -07:00
commit 53138e8289
1 changed files with 3 additions and 26 deletions

View File

@ -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)
}
}
}