From f47f6af585412dc95d49dcc850ec1d07dd6ade64 Mon Sep 17 00:00:00 2001 From: Phil Estes Date: Tue, 23 Jan 2018 10:30:29 -0500 Subject: [PATCH] Remove unnecessary subreaper API from sys/ Given these same exact functions are both now available in opencontainers/runc (libcontainer/system) package, and we only use the `SetSubreaper` today from the shim, there seems to be no reason for duplication. Signed-off-by: Phil Estes --- cmd/containerd-shim/shim_linux.go | 4 +-- sys/prctl.go | 41 ------------------------------- 2 files changed, 2 insertions(+), 43 deletions(-) delete mode 100644 sys/prctl.go diff --git a/cmd/containerd-shim/shim_linux.go b/cmd/containerd-shim/shim_linux.go index aa86790bf..0faa59856 100644 --- a/cmd/containerd-shim/shim_linux.go +++ b/cmd/containerd-shim/shim_linux.go @@ -6,8 +6,8 @@ import ( "syscall" "github.com/containerd/containerd/reaper" - "github.com/containerd/containerd/sys" runc "github.com/containerd/go-runc" + "github.com/opencontainers/runc/libcontainer/system" "github.com/stevvooe/ttrpc" ) @@ -20,7 +20,7 @@ func setupSignals() (chan os.Signal, error) { // for waiting on processes runc.Monitor = reaper.Default // set the shim as the subreaper for all orphaned processes created by the container - if err := sys.SetSubreaper(1); err != nil { + if err := system.SetSubreaper(1); err != nil { return nil, err } return signals, nil diff --git a/sys/prctl.go b/sys/prctl.go deleted file mode 100644 index aa1a4ad38..000000000 --- a/sys/prctl.go +++ /dev/null @@ -1,41 +0,0 @@ -// +build linux - -// Package sys provides access to the Get Child and Set Child prctl flags. -// See http://man7.org/linux/man-pages/man2/prctl.2.html -package sys - -import ( - "unsafe" - - "golang.org/x/sys/unix" -) - -// GetSubreaper returns the subreaper setting for the calling process -func GetSubreaper() (int, error) { - var i uintptr - // PR_GET_CHILD_SUBREAPER allows retrieving the current child - // subreaper. - // Returns the "child subreaper" setting of the caller, in the - // location pointed to by (int *) arg2. - if err := unix.Prctl(unix.PR_GET_CHILD_SUBREAPER, uintptr(unsafe.Pointer(&i)), 0, 0, 0); err != nil { - 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 { - // 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. - return unix.Prctl(unix.PR_SET_CHILD_SUBREAPER, uintptr(i), 0, 0, 0) -}