1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

minor cleanup for signal handling

This commit is contained in:
unclejack 2013-08-09 23:23:27 +03:00
parent 88cb9f3116
commit 2ba5c91547

View file

@ -1396,15 +1396,12 @@ func (cli *DockerCli) CmdRun(args ...string) error {
signals := make(chan os.Signal, 1) signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM) signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM)
go func() { go func() {
for { for sig := range signals {
sig := <-signals
if sig == syscall.SIGINT || sig == syscall.SIGTERM {
fmt.Printf("\nReceived signal: %s; cleaning up\n", sig) fmt.Printf("\nReceived signal: %s; cleaning up\n", sig)
if err := cli.CmdStop("-t", "4", runResult.ID); err != nil { if err := cli.CmdStop("-t", "4", runResult.ID); err != nil {
fmt.Printf("failed to stop container:", err) fmt.Printf("failed to stop container:", err)
} }
} }
}
}() }()
if err := cli.hijack("POST", "/containers/"+runResult.ID+"/attach?"+v.Encode(), config.Tty, cli.in, cli.out); err != nil { if err := cli.hijack("POST", "/containers/"+runResult.ID+"/attach?"+v.Encode(), config.Tty, cli.in, cli.out); err != nil {