Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Terraform
Commits
e9c35eae
Unverified
Commit
e9c35eae
authored
8 years ago
by
Mitchell Hashimoto
Browse files
Options
Download
Email Patches
Plain Diff
Forward SIGTERM and handle that as an interrupt
parent
9c80c82d
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
commands.go
+2
-1
commands.go
main.go
+2
-1
main.go
signal_unix.go
+2
-4
signal_unix.go
signal_windows.go
+2
-1
signal_windows.go
vendor/github.com/mitchellh/panicwrap/panicwrap.go
+14
-0
vendor/github.com/mitchellh/panicwrap/panicwrap.go
vendor/vendor.json
+3
-3
vendor/vendor.json
with
25 additions
and
10 deletions
+25
-10
commands.go
+
2
-
1
View file @
e9c35eae
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
main.go
+
2
-
1
View file @
e9c35eae
...
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
signal_unix.go
+
2
-
4
View file @
e9c35eae
...
...
@@ -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
}
This diff is collapsed.
Click to expand it.
signal_windows.go
+
2
-
1
View file @
e9c35eae
...
...
@@ -6,4 +6,5 @@ import (
"os"
)
var
interruptSignals
[]
os
.
Signal
=
[]
os
.
Signal
{
os
.
Interrupt
}
var
ignoreSignals
=
[]
os
.
Signal
{
os
.
Interrupt
}
var
forwardSignals
[]
os
.
Signal
This diff is collapsed.
Click to expand it.
vendor/github.com/mitchellh/panicwrap/panicwrap.go
+
14
-
0
View file @
e9c35eae
...
...
@@ -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
:
}
}
...
...
This diff is collapsed.
Click to expand it.
vendor/vendor.json
+
3
-
3
View file @
e9c35eae
...
...
@@ -2079,10 +2079,10 @@
"revision"
:
"314aad379a39f6ad5bcca278e6757d9abbb3a52e"
},
{
"checksumSHA1"
:
"
kTntIB9SdU1NsCqKwDkUr99qaj
0="
,
"checksumSHA1"
:
"
AykrbOR+O+Yp6DQHfwe31+iyFi
0="
,
"path"
:
"github.com/mitchellh/panicwrap"
,
"revision"
:
"
fde185d0dfb5ecac6e6b201e8855da798ebcd76f
"
,
"revisionTime"
:
"2016-1
1-21T18:34:54
Z"
"revision"
:
"
ba9e1a65e0f7975f055d50a2c0201c50d941c24c
"
,
"revisionTime"
:
"2016-1
2-08T17:03:02
Z"
},
{
"path"
:
"github.com/mitchellh/prefixedio"
,
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment