Add WithProcessKill DeleteOpt
Add an option that allows users for force kill and delete a process/task when calling `Delete` Fixes #1274 Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
19
task_opts.go
19
task_opts.go
@@ -2,6 +2,7 @@ package containerd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"syscall"
|
||||
|
||||
"github.com/containerd/containerd/linux/runcopts"
|
||||
"github.com/containerd/containerd/mount"
|
||||
@@ -25,3 +26,21 @@ func WithExit(r *CheckpointTaskInfo) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ProcessDeleteOpts allows the caller to set options for the deletion of a task
|
||||
type ProcessDeleteOpts func(context.Context, Process) error
|
||||
|
||||
// WithProcessKill will forcefully kill and delete a process
|
||||
func WithProcessKill(ctx context.Context, p Process) error {
|
||||
s := make(chan struct{}, 1)
|
||||
// ignore errors to wait and kill as we are forcefully killing
|
||||
// the process and don't care about the exit status
|
||||
go func() {
|
||||
p.Wait(ctx)
|
||||
close(s)
|
||||
}()
|
||||
p.Kill(ctx, syscall.SIGKILL)
|
||||
// wait for the process to fully stop before letting the rest of the deletion complete
|
||||
<-s
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user