Merge pull request #2986 from thaJeztah/ignore_nil_signals

ForwardAllSignals: check if channel is closed, and remove warning
This commit is contained in:
Silvin Lubecki 2021-05-25 10:29:42 +02:00 committed by GitHub
commit e26409ebf1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 4 deletions

View File

@ -2,7 +2,6 @@ package container
import ( import (
"context" "context"
"fmt"
"os" "os"
gosignal "os/signal" gosignal "os/signal"
@ -15,10 +14,16 @@ import (
// //
// The channel you pass in must already be setup to receive any signals you want to forward. // The channel you pass in must already be setup to receive any signals you want to forward.
func ForwardAllSignals(ctx context.Context, cli command.Cli, cid string, sigc <-chan os.Signal) { func ForwardAllSignals(ctx context.Context, cli command.Cli, cid string, sigc <-chan os.Signal) {
var s os.Signal var (
s os.Signal
ok bool
)
for { for {
select { select {
case s = <-sigc: case s, ok = <-sigc:
if !ok {
return
}
case <-ctx.Done(): case <-ctx.Done():
return return
} }
@ -40,7 +45,6 @@ func ForwardAllSignals(ctx context.Context, cli command.Cli, cid string, sigc <-
} }
} }
if sig == "" { if sig == "" {
fmt.Fprintf(cli.Err(), "Unsupported signal: %v. Discarding.\n", s)
continue continue
} }