diff options
| author | Cherry Zhang <cherryyz@google.com> | 2019-10-04 16:55:52 -0400 |
|---|---|---|
| committer | Cherry Zhang <cherryyz@google.com> | 2019-10-04 16:55:52 -0400 |
| commit | b0d930577ebe86d0dbd6d3f4bf551a4e4ff1fcde (patch) | |
| tree | c1382943d8874ef6f278b1b49d38b4a5090993a8 /src/os | |
| parent | e63c1df34856fbf61f72fef84f810cf3306ec204 (diff) | |
| parent | c450ace12c657e3953d79975c04f51605395cd50 (diff) | |
| download | go-b0d930577ebe86d0dbd6d3f4bf551a4e4ff1fcde.tar.xz | |
[dev.link] all: merge branch 'master' into dev.link
Weekly merge.
Change-Id: I98c6121f04f347df2788ac5eaf99afad5da4a039
Diffstat (limited to 'src/os')
| -rw-r--r-- | src/os/exec/exec.go | 8 | ||||
| -rw-r--r-- | src/os/signal/signal.go | 15 | ||||
| -rw-r--r-- | src/os/signal/signal_plan9.go | 3 | ||||
| -rw-r--r-- | src/os/signal/signal_unix.go | 3 |
4 files changed, 23 insertions, 6 deletions
diff --git a/src/os/exec/exec.go b/src/os/exec/exec.go index 17ef003eca..19c7e2406a 100644 --- a/src/os/exec/exec.go +++ b/src/os/exec/exec.go @@ -606,8 +606,8 @@ func (c *closeOnce) close() { // standard output when the command starts. // // Wait will close the pipe after seeing the command exit, so most callers -// need not close the pipe themselves; however, an implication is that -// it is incorrect to call Wait before all reads from the pipe have completed. +// need not close the pipe themselves. It is thus incorrect to call Wait +// before all reads from the pipe have completed. // For the same reason, it is incorrect to call Run when using StdoutPipe. // See the example for idiomatic usage. func (c *Cmd) StdoutPipe() (io.ReadCloser, error) { @@ -631,8 +631,8 @@ func (c *Cmd) StdoutPipe() (io.ReadCloser, error) { // standard error when the command starts. // // Wait will close the pipe after seeing the command exit, so most callers -// need not close the pipe themselves; however, an implication is that -// it is incorrect to call Wait before all reads from the pipe have completed. +// need not close the pipe themselves. It is thus incorrect to call Wait +// before all reads from the pipe have completed. // For the same reason, it is incorrect to use Run when using StderrPipe. // See the StdoutPipe example for idiomatic usage. func (c *Cmd) StderrPipe() (io.ReadCloser, error) { diff --git a/src/os/signal/signal.go b/src/os/signal/signal.go index a0eba0d50f..136dd9cc97 100644 --- a/src/os/signal/signal.go +++ b/src/os/signal/signal.go @@ -92,6 +92,15 @@ func Ignored(sig os.Signal) bool { return sn >= 0 && signalIgnored(sn) } +var ( + // watchSignalLoopOnce guards calling the conditionally + // initialized watchSignalLoop. If watchSignalLoop is non-nil, + // it will be run in a goroutine lazily once Notify is invoked. + // See Issue 21576. + watchSignalLoopOnce sync.Once + watchSignalLoop func() +) + // Notify causes package signal to relay incoming signals to c. // If no signals are provided, all incoming signals will be relayed to c. // Otherwise, just the provided signals will. @@ -113,6 +122,12 @@ func Notify(c chan<- os.Signal, sig ...os.Signal) { panic("os/signal: Notify using nil channel") } + watchSignalLoopOnce.Do(func() { + if watchSignalLoop != nil { + go watchSignalLoop() + } + }) + handlers.Lock() defer handlers.Unlock() diff --git a/src/os/signal/signal_plan9.go b/src/os/signal/signal_plan9.go index a1eb68855e..8408607c7f 100644 --- a/src/os/signal/signal_plan9.go +++ b/src/os/signal/signal_plan9.go @@ -20,7 +20,8 @@ func signal_recv() string func init() { signal_enable(0) // first call - initialize - go loop() + + watchSignalLoop = loop } func loop() { diff --git a/src/os/signal/signal_unix.go b/src/os/signal/signal_unix.go index 7fa634f15a..0bbf41bfde 100644 --- a/src/os/signal/signal_unix.go +++ b/src/os/signal/signal_unix.go @@ -26,7 +26,8 @@ func loop() { func init() { signal_enable(0) // first call - initialize - go loop() + + watchSignalLoop = loop } const ( |
