Add utility functions to set process as subreaper.
This code is borrowed from libcontainer system package. Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
This commit is contained in:
parent
c13dbaf6ab
commit
7c5fccd7a8
1 changed files with 17 additions and 0 deletions
|
@ -3,8 +3,11 @@ package utils
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const PR_SET_CHILD_SUBREAPER = 36
|
||||||
|
|
||||||
func ExecCmd(name string, args ...string) (string, error) {
|
func ExecCmd(name string, args ...string) (string, error) {
|
||||||
cmd := exec.Command(name, args...)
|
cmd := exec.Command(name, args...)
|
||||||
var out bytes.Buffer
|
var out bytes.Buffer
|
||||||
|
@ -17,3 +20,17 @@ func ExecCmd(name string, args ...string) (string, error) {
|
||||||
|
|
||||||
return out.String(), nil
|
return out.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetSubreaper sets the value i as the subreaper setting for the calling process
|
||||||
|
func SetSubreaper(i int) error {
|
||||||
|
return Prctl(PR_SET_CHILD_SUBREAPER, uintptr(i), 0, 0, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prctl is a way to make the prctl linux syscall
|
||||||
|
func Prctl(option int, arg2, arg3, arg4, arg5 uintptr) (err error) {
|
||||||
|
_, _, e1 := syscall.Syscall6(syscall.SYS_PRCTL, uintptr(option), arg2, arg3, arg4, arg5, 0)
|
||||||
|
if e1 != 0 {
|
||||||
|
err = e1
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue