github.com/dims/containerd@v0.2.5/osutils/prctl.go (about) 1 // +build linux 2 3 // Package osutils provide access to the Get Child and Set Child prctl 4 // flags. 5 // See http://man7.org/linux/man-pages/man2/prctl.2.html 6 package osutils 7 8 import ( 9 "syscall" 10 "unsafe" 11 ) 12 13 // PR_SET_CHILD_SUBREAPER allows setting the child subreaper. 14 // If arg2 is nonzero, set the "child subreaper" attribute of the 15 // calling process; if arg2 is zero, unset the attribute. When a 16 // process is marked as a child subreaper, all of the children 17 // that it creates, and their descendants, will be marked as 18 // having a subreaper. In effect, a subreaper fulfills the role 19 // of init(1) for its descendant processes. Upon termination of 20 // a process that is orphaned (i.e., its immediate parent has 21 // already terminated) and marked as having a subreaper, the 22 // nearest still living ancestor subreaper will receive a SIGCHLD 23 // signal and be able to wait(2) on the process to discover its 24 // termination status. 25 const prSetChildSubreaper = 36 26 27 // PR_GET_CHILD_SUBREAPER allows retrieving the current child 28 // subreaper. 29 // Return the "child subreaper" setting of the caller, in the 30 // location pointed to by (int *) arg2. 31 const prGetChildSubreaper = 37 32 33 // GetSubreaper returns the subreaper setting for the calling process 34 func GetSubreaper() (int, error) { 35 var i uintptr 36 if _, _, err := syscall.RawSyscall(syscall.SYS_PRCTL, prGetChildSubreaper, uintptr(unsafe.Pointer(&i)), 0); err != 0 { 37 return -1, err 38 } 39 return int(i), nil 40 } 41 42 // SetSubreaper sets the value i as the subreaper setting for the calling process 43 func SetSubreaper(i int) error { 44 if _, _, err := syscall.RawSyscall(syscall.SYS_PRCTL, prSetChildSubreaper, uintptr(i), 0); err != 0 { 45 return err 46 } 47 return nil 48 }