execution/oci: use package sys for subreaper
Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
This commit is contained in:
parent
6a8d5fdd37
commit
851d811eb2
2 changed files with 6 additions and 44 deletions
|
@ -10,6 +10,7 @@ import (
|
||||||
|
|
||||||
"github.com/crosbymichael/go-runc"
|
"github.com/crosbymichael/go-runc"
|
||||||
"github.com/docker/containerd/execution"
|
"github.com/docker/containerd/execution"
|
||||||
|
"github.com/docker/containerd/sys"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -26,10 +27,13 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func New(root string) (*OCIRuntime, error) {
|
func New(root string) (*OCIRuntime, error) {
|
||||||
err := SetSubreaper(1)
|
err := sys.SetSubreaper(1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
go func() {
|
||||||
|
syscall.Wait4(-1, nil, 0, nil)
|
||||||
|
}()
|
||||||
return &OCIRuntime{
|
return &OCIRuntime{
|
||||||
root: root,
|
root: root,
|
||||||
runc: &runc.Runc{
|
runc: &runc.Runc{
|
||||||
|
@ -243,5 +247,6 @@ func (r *OCIRuntime) DeleteProcess(ctx context.Context, c *execution.Container,
|
||||||
ioID := fmt.Sprintf("%s-%s", c.ID(), id)
|
ioID := fmt.Sprintf("%s-%s", c.ID(), id)
|
||||||
r.ios[ioID].cleanup()
|
r.ios[ioID].cleanup()
|
||||||
delete(r.ios, ioID)
|
delete(r.ios, ioID)
|
||||||
|
c.RemoveProcess(id)
|
||||||
return c.StateDir().DeleteProcess(id)
|
return c.StateDir().DeleteProcess(id)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,43 +0,0 @@
|
||||||
package oci
|
|
||||||
|
|
||||||
import (
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
// PR_SET_CHILD_SUBREAPER allows setting the child subreaper.
|
|
||||||
// If arg2 is nonzero, set the "child subreaper" attribute of the
|
|
||||||
// calling process; if arg2 is zero, unset the attribute. When a
|
|
||||||
// process is marked as a child subreaper, all of the children
|
|
||||||
// that it creates, and their descendants, will be marked as
|
|
||||||
// having a subreaper. In effect, a subreaper fulfills the role
|
|
||||||
// of init(1) for its descendant processes. Upon termination of
|
|
||||||
// a process that is orphaned (i.e., its immediate parent has
|
|
||||||
// already terminated) and marked as having a subreaper, the
|
|
||||||
// nearest still living ancestor subreaper will receive a SIGCHLD
|
|
||||||
// signal and be able to wait(2) on the process to discover its
|
|
||||||
// termination status.
|
|
||||||
const prSetChildSubreaper = 36
|
|
||||||
|
|
||||||
// PR_GET_CHILD_SUBREAPER allows retrieving the current child
|
|
||||||
// subreaper.
|
|
||||||
// Return the "child subreaper" setting of the caller, in the
|
|
||||||
// location pointed to by (int *) arg2.
|
|
||||||
const prGetChildSubreaper = 37
|
|
||||||
|
|
||||||
// GetSubreaper returns the subreaper setting for the calling process
|
|
||||||
func GetSubreaper() (int, error) {
|
|
||||||
var i uintptr
|
|
||||||
if _, _, err := syscall.RawSyscall(syscall.SYS_PRCTL, prGetChildSubreaper, uintptr(unsafe.Pointer(&i)), 0); err != 0 {
|
|
||||||
return -1, err
|
|
||||||
}
|
|
||||||
return int(i), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetSubreaper sets the value i as the subreaper setting for the calling process
|
|
||||||
func SetSubreaper(i int) error {
|
|
||||||
if _, _, err := syscall.RawSyscall(syscall.SYS_PRCTL, prSetChildSubreaper, uintptr(i), 0); err != 0 {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
Loading…
Reference in a new issue