Merge pull request #174 from crosbymichael/restore-signal-handler
Use signal handler for restore
This commit is contained in:
commit
53138e8289
29
restore.go
29
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue