move process terminate operation to defer function

Signed-off-by: lifubang <lifubang@acmcoder.com>
This commit is contained in:
lifubang
2025-03-22 00:08:16 +00:00
committed by Kir Kolyshkin
parent 456d0f525a
commit fba5a1ec23
+6 -5
View File
@@ -286,22 +286,23 @@ func (r *runner) run(config *specs.Process) (_ int, retErr 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)
}
}()
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 detach {
return 0, nil
}