MCPcopy
hub / github.com/opencontainers/runc / newSignalHandler

Function newSignalHandler

signals.go:21–48  ·  view source on GitHub ↗

newSignalHandler returns a signal handler for processing SIGCHLD and SIGWINCH signals while still forwarding all other signals to the process. If notifySocket is present, use it to read systemd notifications from the container and forward them to notifySocketHost.

(enableSubreaper bool, notifySocket *notifySocket)

Source from the content-addressed store, hash-verified

19// If notifySocket is present, use it to read systemd notifications from the container and
20// forward them to notifySocketHost.
21func newSignalHandler(enableSubreaper bool, notifySocket *notifySocket) chan *signalHandler {
22 if enableSubreaper {
23 // set us as the subreaper before registering the signal handler for the container
24 if err := system.SetSubreaper(1); err != nil {
25 logrus.Warn(err)
26 }
27 }
28 handler := make(chan *signalHandler)
29
30 // Ensure that we have a large buffer size so that we do not miss any
31 // signals in case we are not processing them fast enough.
32 s := make(chan os.Signal, signalBufferSize)
33
34 // signal.Notify is actually quite expensive, as it has to configure the
35 // signal mask and add signal handlers for all signals (all ~65 of them).
36 // So, defer this to a background thread while doing the rest of the io/tty
37 // setup, except for SIGCHLD which is very important (see #5208).
38 signal.Notify(s, unix.SIGCHLD)
39 go func() {
40 // handle all signals for the process.
41 signal.Notify(s)
42 handler <- &signalHandler{
43 signals: s,
44 notifySocket: notifySocket,
45 }
46 }()
47 return handler
48}
49
50// exit models a process exit status with the pid and
51// exit status.

Callers 1

runMethod · 0.85

Calls 1

SetSubreaperFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…