vendor: update panicwrap
This commit is contained in:
parent
0bb8ab9afb
commit
a2f6bc628a
|
@ -12,13 +12,15 @@ package panicwrap
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/kardianos/osext"
|
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"sync/atomic"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/kardianos/osext"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -61,6 +63,10 @@ type WrapConfig struct {
|
||||||
// The writer to send stdout to. If this is nil, then it defaults to
|
// The writer to send stdout to. If this is nil, then it defaults to
|
||||||
// os.Stdout.
|
// os.Stdout.
|
||||||
Stdout io.Writer
|
Stdout io.Writer
|
||||||
|
|
||||||
|
// Catch and igore these signals in the parent process, let the child
|
||||||
|
// handle them gracefully.
|
||||||
|
IgnoreSignals []os.Signal
|
||||||
}
|
}
|
||||||
|
|
||||||
// BasicWrap calls Wrap with the given handler function, using defaults
|
// BasicWrap calls Wrap with the given handler function, using defaults
|
||||||
|
@ -145,6 +151,7 @@ func Wrap(c *WrapConfig) (int, error) {
|
||||||
cmd.Stdin = os.Stdin
|
cmd.Stdin = os.Stdin
|
||||||
cmd.Stdout = stdout_w
|
cmd.Stdout = stdout_w
|
||||||
cmd.Stderr = stderr_w
|
cmd.Stderr = stderr_w
|
||||||
|
cmd.ExtraFiles = []*os.File{os.Stdin, os.Stdout, os.Stderr}
|
||||||
if err := cmd.Start(); err != nil {
|
if err := cmd.Start(); err != nil {
|
||||||
return 1, err
|
return 1, err
|
||||||
}
|
}
|
||||||
|
@ -152,7 +159,10 @@ func Wrap(c *WrapConfig) (int, error) {
|
||||||
// Listen to signals and capture them forever. We allow the child
|
// Listen to signals and capture them forever. We allow the child
|
||||||
// process to handle them in some way.
|
// process to handle them in some way.
|
||||||
sigCh := make(chan os.Signal)
|
sigCh := make(chan os.Signal)
|
||||||
signal.Notify(sigCh, os.Interrupt)
|
if len(c.IgnoreSignals) == 0 {
|
||||||
|
c.IgnoreSignals = []os.Signal{os.Interrupt}
|
||||||
|
}
|
||||||
|
signal.Notify(sigCh, c.IgnoreSignals...)
|
||||||
go func() {
|
go func() {
|
||||||
defer signal.Stop(sigCh)
|
defer signal.Stop(sigCh)
|
||||||
for {
|
for {
|
||||||
|
@ -200,7 +210,17 @@ func Wrap(c *WrapConfig) (int, error) {
|
||||||
//
|
//
|
||||||
// Wrapped is very cheap and can be used early to short-circuit some pre-wrap
|
// Wrapped is very cheap and can be used early to short-circuit some pre-wrap
|
||||||
// logic your application may have.
|
// logic your application may have.
|
||||||
|
//
|
||||||
|
// If the given configuration is nil, then this will return a cached
|
||||||
|
// value of Wrapped. This is useful because Wrapped is usually called early
|
||||||
|
// to verify a process hasn't been wrapped before wrapping. After this,
|
||||||
|
// the value of Wrapped hardly changes and is process-global, so other
|
||||||
|
// libraries can check with Wrapped(nil).
|
||||||
func Wrapped(c *WrapConfig) bool {
|
func Wrapped(c *WrapConfig) bool {
|
||||||
|
if c == nil {
|
||||||
|
return wrapCache.Load().(bool)
|
||||||
|
}
|
||||||
|
|
||||||
if c.CookieKey == "" {
|
if c.CookieKey == "" {
|
||||||
c.CookieKey = DEFAULT_COOKIE_KEY
|
c.CookieKey = DEFAULT_COOKIE_KEY
|
||||||
}
|
}
|
||||||
|
@ -211,7 +231,16 @@ func Wrapped(c *WrapConfig) bool {
|
||||||
|
|
||||||
// If the cookie key/value match our environment, then we are the
|
// If the cookie key/value match our environment, then we are the
|
||||||
// child, so just exit now and tell the caller that we're the child
|
// child, so just exit now and tell the caller that we're the child
|
||||||
return os.Getenv(c.CookieKey) == c.CookieValue
|
result := os.Getenv(c.CookieKey) == c.CookieValue
|
||||||
|
wrapCache.Store(result)
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
// wrapCache is the cached value for Wrapped when called with nil
|
||||||
|
var wrapCache atomic.Value
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
wrapCache.Store(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// trackPanic monitors the given reader for a panic. If a panic is detected,
|
// trackPanic monitors the given reader for a panic. If a panic is detected,
|
||||||
|
|
|
@ -1916,8 +1916,10 @@
|
||||||
"revision": "314aad379a39f6ad5bcca278e6757d9abbb3a52e"
|
"revision": "314aad379a39f6ad5bcca278e6757d9abbb3a52e"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"checksumSHA1": "wqU8bs9c+xm0f07t6ajQFWYS+rE=",
|
||||||
"path": "github.com/mitchellh/panicwrap",
|
"path": "github.com/mitchellh/panicwrap",
|
||||||
"revision": "a1e50bc201f387747a45ffff020f1af2d8759e88"
|
"revision": "168f3680ad986108df63bae07da2978f51c4ac8e",
|
||||||
|
"revisionTime": "2016-11-14T06:37:33Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"path": "github.com/mitchellh/prefixedio",
|
"path": "github.com/mitchellh/prefixedio",
|
||||||
|
|
Loading…
Reference in New Issue