Skip to content

Commit

Permalink
skip setup signal notifier for detached container
Browse files Browse the repository at this point in the history
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 <lifubang@acmcoder.com>
  • Loading branch information
lifubang committed Mar 5, 2025
1 parent 2f93d66 commit 9d4b664
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions signals.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,23 @@ const signalBufferSize = 2048
// 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.
func newSignalHandler(enableSubreaper bool, notifySocket *notifySocket) chan *signalHandler {
func newSignalHandler(enableSubreaper bool, detach bool, notifySocket *notifySocket) chan *signalHandler {
if enableSubreaper {
// set us as the subreaper before registering the signal handler for the container
if err := system.SetSubreaper(1); err != nil {
logrus.Warn(err)
}
}
handler := make(chan *signalHandler)
handler := make(chan *signalHandler, 1)
// For detached container, we don't need to setup signal notifier, because
// there is no customer to consume the signals in `forward()`.
if detach {
handler <- &signalHandler{
signals: nil,
notifySocket: notifySocket,
}
return handler
}
// signal.Notify is actually quite expensive, as it has to configure the
// signal mask and add signal handlers for all signals (all ~65 of them).
// So, defer this to a background thread while doing the rest of the io/tty
Expand Down
2 changes: 1 addition & 1 deletion utils_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func (r *runner) run(config *specs.Process) (int, error) {
// Setting up IO is a two stage process. We need to modify process to deal
// with detaching containers, and then we get a tty after the container has
// started.
handlerCh := newSignalHandler(r.enableSubreaper, r.notifySocket)
handlerCh := newSignalHandler(detach, r.enableSubreaper, r.notifySocket)
tty, err := setupIO(process, r.container, config.Terminal, detach, r.consoleSocket)
if err != nil {
return -1, err
Expand Down

0 comments on commit 9d4b664

Please sign in to comment.