ForwardAllSignals forwards signals to the container The channel you pass in must already be setup to receive any signals you want to forward.
(ctx context.Context, apiClient client.ContainerAPIClient, cid string, sigc <-chan os.Signal)
| 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 | _, err := apiClient.ContainerKill(ctx, cid, client.ContainerKillOptions{ |
| 52 | Signal: sig, |
| 53 | }) |
| 54 | if err != nil { |
| 55 | logrus.Debugf("Error sending signal: %s", err) |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | func notifyAllSignals() chan os.Signal { |
| 61 | sigc := make(chan os.Signal, 128) |
searching dependent graphs…