mirror of
https://github.com/rancher/os.git
synced 2025-08-31 22:32:14 +00:00
Update vendor
This commit is contained in:
18
vendor/github.com/docker/containerd/osutils/fds.go
generated
vendored
Normal file
18
vendor/github.com/docker/containerd/osutils/fds.go
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
// +build !windows,!darwin
|
||||
|
||||
package osutils
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// GetOpenFds returns the number of open fds for the process provided by pid
|
||||
func GetOpenFds(pid int) (int, error) {
|
||||
dirs, err := ioutil.ReadDir(filepath.Join("/proc", strconv.Itoa(pid), "fd"))
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
return len(dirs), nil
|
||||
}
|
43
vendor/github.com/docker/containerd/osutils/prctl.go
generated
vendored
Normal file
43
vendor/github.com/docker/containerd/osutils/prctl.go
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
// +build linux
|
||||
|
||||
// http://man7.org/linux/man-pages/man2/prctl.2.html
|
||||
package osutils
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// 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 PR_SET_CHILD_SUBREAPER = 36
|
||||
|
||||
// Return the "child subreaper" setting of the caller, in the
|
||||
// location pointed to by (int *) arg2.
|
||||
const PR_GET_CHILD_SUBREAPER = 37
|
||||
|
||||
// GetSubreaper returns the subreaper setting for the calling process
|
||||
func GetSubreaper() (int, error) {
|
||||
var i uintptr
|
||||
if _, _, err := syscall.RawSyscall(syscall.SYS_PRCTL, PR_GET_CHILD_SUBREAPER, 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, PR_SET_CHILD_SUBREAPER, uintptr(i), 0); err != 0 {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
18
vendor/github.com/docker/containerd/osutils/prctl_solaris.go
generated
vendored
Normal file
18
vendor/github.com/docker/containerd/osutils/prctl_solaris.go
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
// +build solaris
|
||||
|
||||
package osutils
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
//Solaris TODO
|
||||
// GetSubreaper returns the subreaper setting for the calling process
|
||||
func GetSubreaper() (int, error) {
|
||||
return 0, errors.New("osutils GetSubreaper not implemented on Solaris")
|
||||
}
|
||||
|
||||
// SetSubreaper sets the value i as the subreaper setting for the calling process
|
||||
func SetSubreaper(i int) error {
|
||||
return errors.New("osutils SetSubreaper not implemented on Solaris")
|
||||
}
|
47
vendor/github.com/docker/containerd/osutils/reaper.go
generated
vendored
Normal file
47
vendor/github.com/docker/containerd/osutils/reaper.go
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
// +build !windows
|
||||
|
||||
package osutils
|
||||
|
||||
import "syscall"
|
||||
|
||||
// Exit is the wait4 information from an exited process
|
||||
type Exit struct {
|
||||
Pid int
|
||||
Status int
|
||||
}
|
||||
|
||||
// Reap reaps all child processes for the calling process and returns their
|
||||
// exit information
|
||||
func Reap() (exits []Exit, err error) {
|
||||
var (
|
||||
ws syscall.WaitStatus
|
||||
rus syscall.Rusage
|
||||
)
|
||||
for {
|
||||
pid, err := syscall.Wait4(-1, &ws, syscall.WNOHANG, &rus)
|
||||
if err != nil {
|
||||
if err == syscall.ECHILD {
|
||||
return exits, nil
|
||||
}
|
||||
return exits, err
|
||||
}
|
||||
if pid <= 0 {
|
||||
return exits, nil
|
||||
}
|
||||
exits = append(exits, Exit{
|
||||
Pid: pid,
|
||||
Status: exitStatus(ws),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const exitSignalOffset = 128
|
||||
|
||||
// exitStatus returns the correct exit status for a process based on if it
|
||||
// was signaled or exited cleanly
|
||||
func exitStatus(status syscall.WaitStatus) int {
|
||||
if status.Signaled() {
|
||||
return exitSignalOffset + int(status.Signal())
|
||||
}
|
||||
return status.ExitStatus()
|
||||
}
|
Reference in New Issue
Block a user