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:
Michael Crosby
2017-08-07 16:10:43 -04:00
parent d4be9822ed
commit d8c075aadc
4 changed files with 181 additions and 3 deletions

View File

@@ -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
}