-
Notifications
You must be signed in to change notification settings - Fork 2.3k
skip setup signal notifier for detached container #4661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ import ( | |
| "github.com/opencontainers/runc/libcontainer" | ||
| "github.com/opencontainers/runc/libcontainer/configs" | ||
| "github.com/opencontainers/runc/libcontainer/specconv" | ||
| "github.com/opencontainers/runc/libcontainer/system" | ||
| "github.com/opencontainers/runc/libcontainer/system/kernelversion" | ||
| "github.com/opencontainers/runc/libcontainer/utils" | ||
| ) | ||
|
|
@@ -219,14 +220,16 @@ type runner struct { | |
| subCgroupPaths map[string]string | ||
| } | ||
|
|
||
| func (r *runner) run(config *specs.Process) (int, error) { | ||
| var err error | ||
| func (r *runner) run(config *specs.Process) (_ int, retErr error) { | ||
| detach := r.detach || (r.action == CT_ACT_CREATE) | ||
| defer func() { | ||
| if err != nil { | ||
| // For a non-detached container, or we get an error, we | ||
| // should destroy the container. | ||
| if !detach || retErr != nil { | ||
|
lifubang marked this conversation as resolved.
rata marked this conversation as resolved.
rata marked this conversation as resolved.
|
||
| r.destroy() | ||
| } | ||
| }() | ||
| if err = r.checkTerminal(config); err != nil { | ||
| if err := r.checkTerminal(config); err != nil { | ||
| return -1, err | ||
| } | ||
| process, err := newProcess(config) | ||
|
|
@@ -255,11 +258,19 @@ func (r *runner) run(config *specs.Process) (int, error) { | |
| } | ||
| process.ExtraFiles = append(process.ExtraFiles, os.NewFile(uintptr(i), "PreserveFD:"+strconv.Itoa(i))) | ||
| } | ||
| detach := r.detach || (r.action == CT_ACT_CREATE) | ||
| // 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) | ||
| if r.enableSubreaper { | ||
| // set us as the subreaper before registering the signal handler for the container | ||
|
rata marked this conversation as resolved.
|
||
| if err := system.SetSubreaper(1); err != nil { | ||
|
rata marked this conversation as resolved.
|
||
| logrus.Warn(err) | ||
| } | ||
| } | ||
| var handlerCh chan *signalHandler | ||
| if !detach { | ||
| handlerCh = newSignalHandler() | ||
| } | ||
| tty, err := setupIO(process, r.container, config.Terminal, detach, r.consoleSocket) | ||
| if err != nil { | ||
| return -1, err | ||
|
|
@@ -287,29 +298,32 @@ func (r *runner) run(config *specs.Process) (int, error) { | |
| if err != nil { | ||
| return -1, err | ||
| } | ||
| defer func() { | ||
| // We should terminate the process once we got an error. | ||
| if retErr != nil { | ||
| r.terminate(process) | ||
|
Comment on lines
+301
to
+304
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is duplicated now. The function deferred previously will also do the exact same thing. Is this on purpose?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Therefore, was this also unnecessary in the past? I suggest we keep it, as there may have been scenarios we haven't taken into account. |
||
| } | ||
| }() | ||
| if err = tty.waitConsole(); err != nil { | ||
| r.terminate(process) | ||
| return -1, err | ||
| } | ||
| tty.ClosePostStart() | ||
| if r.pidFile != "" { | ||
| if err = createPidFile(r.pidFile, process); err != nil { | ||
| r.terminate(process) | ||
| return -1, err | ||
| } | ||
| } | ||
| handler := <-handlerCh | ||
| status, err := handler.forward(process, tty, detach) | ||
| if err != nil { | ||
| r.terminate(process) | ||
| if r.notifySocket != nil { | ||
| if err = r.notifySocket.forward(process, detach); err != nil { | ||
| return -1, err | ||
|
rata marked this conversation as resolved.
|
||
| } | ||
| } | ||
| if detach { | ||
| return 0, nil | ||
| } | ||
| if err == nil { | ||
| r.destroy() | ||
| } | ||
| return status, err | ||
| // For non-detached container, we should forward signals to the container. | ||
| handler := <-handlerCh | ||
| return handler.forward(process, tty) | ||
| } | ||
|
|
||
| func (r *runner) destroy() { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.