diff --git a/commands.go b/commands.go index b7492db35..e4abaf0b2 100644 --- a/commands.go +++ b/commands.go @@ -223,7 +223,8 @@ func makeShutdownCh() <-chan struct{} { resultCh := make(chan struct{}) signalCh := make(chan os.Signal, 4) - signal.Notify(signalCh, interruptSignals...) + signal.Notify(signalCh, ignoreSignals...) + signal.Notify(signalCh, forwardSignals...) go func() { for { <-signalCh diff --git a/main.go b/main.go index 9ee3c7fb6..bcf6a3f58 100644 --- a/main.go +++ b/main.go @@ -60,7 +60,8 @@ func realMain() int { wrapConfig.Handler = panicHandler(logTempFile) wrapConfig.Writer = io.MultiWriter(logTempFile, logWriter) wrapConfig.Stdout = outW - wrapConfig.IgnoreSignals = interruptSignals + wrapConfig.IgnoreSignals = ignoreSignals + wrapConfig.ForwardSignals = forwardSignals exitStatus, err := panicwrap.Wrap(&wrapConfig) if err != nil { fmt.Fprintf(os.Stderr, "Couldn't start Terraform: %s", err) diff --git a/signal_unix.go b/signal_unix.go index 65669a746..573964cfe 100644 --- a/signal_unix.go +++ b/signal_unix.go @@ -7,7 +7,5 @@ import ( "syscall" ) -var interruptSignals []os.Signal = []os.Signal{ - os.Interrupt, - syscall.SIGTERM, -} +var ignoreSignals = []os.Signal{os.Interrupt} +var forwardSignals = []os.Signal{syscall.SIGTERM} diff --git a/signal_windows.go b/signal_windows.go index 885df4ee4..ad1da298e 100644 --- a/signal_windows.go +++ b/signal_windows.go @@ -6,4 +6,5 @@ import ( "os" ) -var interruptSignals []os.Signal = []os.Signal{os.Interrupt} +var ignoreSignals = []os.Signal{os.Interrupt} +var forwardSignals []os.Signal diff --git a/vendor/github.com/mitchellh/panicwrap/panicwrap.go b/vendor/github.com/mitchellh/panicwrap/panicwrap.go index f5ce93f0b..160ed828c 100644 --- a/vendor/github.com/mitchellh/panicwrap/panicwrap.go +++ b/vendor/github.com/mitchellh/panicwrap/panicwrap.go @@ -68,6 +68,13 @@ type WrapConfig struct { // Catch and igore these signals in the parent process, let the child // handle them gracefully. IgnoreSignals []os.Signal + + // Catch these signals in the parent process and manually forward + // them to the child process. Some signals such as SIGINT are usually + // sent to the entire process group so setting it isn't necessary. Other + // signals like SIGTERM are only sent to the parent process and need + // to be forwarded. This defaults to empty. + ForwardSignals []os.Signal } // BasicWrap calls Wrap with the given handler function, using defaults @@ -166,16 +173,23 @@ func Wrap(c *WrapConfig) (int, error) { // Listen to signals and capture them forever. We allow the child // process to handle them in some way. sigCh := make(chan os.Signal) + fwdSigCh := make(chan os.Signal) if len(c.IgnoreSignals) == 0 { c.IgnoreSignals = []os.Signal{os.Interrupt} } signal.Notify(sigCh, c.IgnoreSignals...) + signal.Notify(sigCh, c.ForwardSignals...) go func() { defer signal.Stop(sigCh) + defer signal.Stop(fwdSigCh) for { select { case <-doneCh: return + case s := <-fwdSigCh: + if cmd.Process != nil { + cmd.Process.Signal(s) + } case <-sigCh: } } diff --git a/vendor/vendor.json b/vendor/vendor.json index 5c95e6a8b..6dadc7a0a 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -2079,10 +2079,10 @@ "revision": "314aad379a39f6ad5bcca278e6757d9abbb3a52e" }, { - "checksumSHA1": "kTntIB9SdU1NsCqKwDkUr99qaj0=", + "checksumSHA1": "AykrbOR+O+Yp6DQHfwe31+iyFi0=", "path": "github.com/mitchellh/panicwrap", - "revision": "fde185d0dfb5ecac6e6b201e8855da798ebcd76f", - "revisionTime": "2016-11-21T18:34:54Z" + "revision": "ba9e1a65e0f7975f055d50a2c0201c50d941c24c", + "revisionTime": "2016-12-08T17:03:02Z" }, { "path": "github.com/mitchellh/prefixedio",