Browse code

Return correct exit code upon signal + SIGQUIT now quits without cleanup

Docker-DCO-1.1-Signed-off-by: Guillaume J. Charmes <guillaume@charmes.net> (github: creack)

Guillaume J. Charmes authored on 2014/04/02 21:56:11
Showing 1 changed files
... ...
@@ -54,11 +54,16 @@ func InitServer(job *engine.Job) engine.Status {
54 54
 	c := make(chan os.Signal, 1)
55 55
 	gosignal.Notify(c, os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT)
56 56
 	go func() {
57
-		sig := <-c
58
-		log.Printf("Received signal '%v', starting shutdown of docker...\n", sig)
59
-		utils.RemovePidFile(srv.runtime.Config().Pidfile)
60
-		srv.Close()
61
-		os.Exit(0)
57
+		for sig := range c {
58
+			log.Printf("Received signal '%v', starting shutdown of docker...\n", sig)
59
+			switch sig {
60
+			case os.Interrupt, syscall.SIGTERM:
61
+				utils.RemovePidFile(srv.runtime.Config().Pidfile)
62
+				srv.Close()
63
+			case syscall.SIGQUIT:
64
+			}
65
+			os.Exit(128 + int(sig.(syscall.Signal)))
66
+		}
62 67
 	}()
63 68
 	job.Eng.Hack_SetGlobalVar("httpapi.server", srv)
64 69
 	job.Eng.Hack_SetGlobalVar("httpapi.runtime", srv.runtime)