Skip to content

Commit

Permalink
return error if libcontainer destroy failed
Browse files Browse the repository at this point in the history
Signed-off-by: Zhang Tianyang <burning9699@gmail.com>
  • Loading branch information
Burning1020 committed Oct 31, 2023
1 parent ef1166a commit 3c39079
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ checkpointed.`,
err = container.Checkpoint(options)
if err == nil && !(options.LeaveRunning || options.PreDump) {
// Destroy the container unless we tell CRIU to keep it.
destroy(container)
_ = destroy(container)
}
return err
},
Expand Down
6 changes: 4 additions & 2 deletions delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func killContainer(container *libcontainer.Container) error {
for i := 0; i < 100; i++ {
time.Sleep(100 * time.Millisecond)
if err := container.Signal(unix.Signal(0)); err != nil {
destroy(container)
_ = destroy(container)
return nil
}
}
Expand Down Expand Up @@ -72,7 +72,9 @@ status of "ubuntu01" as "stopped" the following will delete resources held for
}
switch s {
case libcontainer.Stopped:
destroy(container)
if err := destroy(container); err != nil {
return err
}
case libcontainer.Created:
return killContainer(container)
default:
Expand Down
6 changes: 4 additions & 2 deletions utils_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,12 @@ func newProcess(p specs.Process) (*libcontainer.Process, error) {
return lp, nil
}

func destroy(container *libcontainer.Container) {
func destroy(container *libcontainer.Container) error {
if err := container.Destroy(); err != nil {
logrus.Error(err)
return err
}
return nil
}

// setupIO modifies the given process config according to the options.
Expand Down Expand Up @@ -293,7 +295,7 @@ func (r *runner) run(config *specs.Process) (int, error) {

func (r *runner) destroy() {
if r.shouldDestroy {
destroy(r.container)
_ = destroy(r.container)
}
}

Expand Down

0 comments on commit 3c39079

Please sign in to comment.