github.1git.de/docker/cli@v26.1.3+incompatible/cli/command/container/signals.go (about) 1 package container 2 3 import ( 4 "context" 5 "os" 6 gosignal "os/signal" 7 8 "github.com/docker/docker/client" 9 "github.com/moby/sys/signal" 10 "github.com/sirupsen/logrus" 11 ) 12 13 // ForwardAllSignals forwards signals to the container 14 // 15 // The channel you pass in must already be setup to receive any signals you want to forward. 16 func ForwardAllSignals(ctx context.Context, apiClient client.ContainerAPIClient, cid string, sigc <-chan os.Signal) { 17 var ( 18 s os.Signal 19 ok bool 20 ) 21 for { 22 select { 23 case s, ok = <-sigc: 24 if !ok { 25 return 26 } 27 case <-ctx.Done(): 28 return 29 } 30 31 if s == signal.SIGCHLD || s == signal.SIGPIPE { 32 continue 33 } 34 35 // In go1.14+, the go runtime issues SIGURG as an interrupt to support pre-emptable system calls on Linux. 36 // Since we can't forward that along we'll check that here. 37 if isRuntimeSig(s) { 38 continue 39 } 40 var sig string 41 for sigStr, sigN := range signal.SignalMap { 42 if sigN == s { 43 sig = sigStr 44 break 45 } 46 } 47 if sig == "" { 48 continue 49 } 50 51 if err := apiClient.ContainerKill(ctx, cid, sig); err != nil { 52 logrus.Debugf("Error sending signal: %s", err) 53 } 54 } 55 } 56 57 func notifyAllSignals() chan os.Signal { 58 sigc := make(chan os.Signal, 128) 59 gosignal.Notify(sigc) 60 return sigc 61 }