Skip to content

Commit a6f4081

Browse files
committed
libct: Destroy: don't proceed in case of errors
For some reason, container destroy operation removes container's state directory even if cgroup removal fails (and then still returns an error). It has been that way since commit 5c246d0, which added cgroup removal. This is problematic because once the container state dir is removed, we no longer know container's cgroup and thus can't remove it. Let's return the error early and fail if cgroup can't be removed. Same for other operations: do not proceed if we fail. Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent ab3cd8d commit a6f4081

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

libcontainer/state_linux.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,19 @@ func destroy(c *Container) error {
4646
if !c.config.Namespaces.IsPrivate(configs.NEWPID) {
4747
_ = signalAllProcesses(c.cgroupManager, unix.SIGKILL)
4848
}
49-
err := c.cgroupManager.Destroy()
49+
if err := c.cgroupManager.Destroy(); err != nil {
50+
return fmt.Errorf("unable to remove container's cgroup: %w", err)
51+
}
5052
if c.intelRdtManager != nil {
51-
if ierr := c.intelRdtManager.Destroy(); err == nil {
52-
err = ierr
53+
if err := c.intelRdtManager.Destroy(); err != nil {
54+
return fmt.Errorf("unable to remove container's IntelRDT group: %w", err)
5355
}
5456
}
55-
if rerr := os.RemoveAll(c.stateDir); err == nil {
56-
err = rerr
57+
if err := os.RemoveAll(c.stateDir); err != nil {
58+
return fmt.Errorf("unable to remove container state dir: %w", err)
5759
}
5860
c.initProcess = nil
59-
if herr := runPoststopHooks(c); err == nil {
60-
err = herr
61-
}
61+
err := runPoststopHooks(c)
6262
c.state = &stoppedState{c: c}
6363
return err
6464
}

0 commit comments

Comments
 (0)