Skip to content

Commit b2d5924

Browse files
committed
skip setup signal notifier for detached container
For detached container, we don't need to setup signal notifier, because there is no customer to consume the signals in `forward()`. Signed-off-by: lifubang <[email protected]>
1 parent 2f93d66 commit b2d5924

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

signals.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,23 @@ const signalBufferSize = 2048
1818
// while still forwarding all other signals to the process.
1919
// If notifySocket is present, use it to read systemd notifications from the container and
2020
// forward them to notifySocketHost.
21-
func newSignalHandler(enableSubreaper bool, notifySocket *notifySocket) chan *signalHandler {
21+
func newSignalHandler(enableSubreaper bool, detach bool, notifySocket *notifySocket) chan *signalHandler {
2222
if enableSubreaper {
2323
// set us as the subreaper before registering the signal handler for the container
2424
if err := system.SetSubreaper(1); err != nil {
2525
logrus.Warn(err)
2626
}
2727
}
28-
handler := make(chan *signalHandler)
28+
handler := make(chan *signalHandler, 1)
29+
// For detached container, we don't need to setup signal notifier, because
30+
// there is no customer to consume the signals in `forward()`.
31+
if detach {
32+
handler <- &signalHandler{
33+
signals: nil,
34+
notifySocket: notifySocket,
35+
}
36+
return handler
37+
}
2938
// signal.Notify is actually quite expensive, as it has to configure the
3039
// signal mask and add signal handlers for all signals (all ~65 of them).
3140
// So, defer this to a background thread while doing the rest of the io/tty

utils_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ func (r *runner) run(config *specs.Process) (int, error) {
252252
// Setting up IO is a two stage process. We need to modify process to deal
253253
// with detaching containers, and then we get a tty after the container has
254254
// started.
255-
handlerCh := newSignalHandler(r.enableSubreaper, r.notifySocket)
255+
handlerCh := newSignalHandler(r.enableSubreaper, detach, r.notifySocket)
256256
tty, err := setupIO(process, r.container, config.Terminal, detach, r.consoleSocket)
257257
if err != nil {
258258
return -1, err

0 commit comments

Comments
 (0)