Merge pull request #666 from unclejack/remove_duplicate_reaper
utils: remove utils & move code to sys
This commit is contained in:
commit
d43628c930
5 changed files with 7 additions and 57 deletions
|
@ -26,7 +26,6 @@ import (
|
|||
"github.com/docker/containerd/reaper"
|
||||
"github.com/docker/containerd/snapshot"
|
||||
"github.com/docker/containerd/sys"
|
||||
"github.com/docker/containerd/utils"
|
||||
metrics "github.com/docker/go-metrics"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli"
|
||||
|
@ -220,7 +219,7 @@ func serveDebugAPI() error {
|
|||
if path == "" {
|
||||
return errors.New("debug socket path cannot be empty")
|
||||
}
|
||||
l, err := utils.CreateUnixSocket(path)
|
||||
l, err := sys.CreateUnixSocket(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -369,7 +368,7 @@ func serveGRPC(server *grpc.Server) error {
|
|||
if path == "" {
|
||||
return errors.New("--socket path cannot be empty")
|
||||
}
|
||||
l, err := utils.CreateUnixSocket(path)
|
||||
l, err := sys.CreateUnixSocket(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ import (
|
|||
"github.com/docker/containerd/api/services/shim"
|
||||
localShim "github.com/docker/containerd/linux/shim"
|
||||
"github.com/docker/containerd/reaper"
|
||||
"github.com/docker/containerd/utils"
|
||||
"github.com/docker/containerd/sys"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
|
@ -25,7 +25,7 @@ func newShim(path string, remote bool) (shim.ShimClient, error) {
|
|||
return localShim.Client(path), nil
|
||||
}
|
||||
socket := filepath.Join(path, "shim.sock")
|
||||
l, err := utils.CreateUnixSocket(socket)
|
||||
l, err := sys.CreateUnixSocket(socket)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -6,13 +6,13 @@ import (
|
|||
"os/exec"
|
||||
"sync"
|
||||
|
||||
"github.com/docker/containerd/utils"
|
||||
"github.com/docker/containerd/sys"
|
||||
)
|
||||
|
||||
// Reap should be called when the process receives an SIGCHLD. Reap will reap
|
||||
// all exited processes and close their wait channels
|
||||
func Reap() error {
|
||||
exits, err := utils.Reap(false)
|
||||
exits, err := sys.Reap(false)
|
||||
for _, e := range exits {
|
||||
Default.Lock()
|
||||
c, ok := Default.cmds[e.Pid]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package utils
|
||||
package sys
|
||||
|
||||
import (
|
||||
"net"
|
|
@ -1,49 +0,0 @@
|
|||
package utils
|
||||
|
||||
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(wait bool) (exits []Exit, err error) {
|
||||
var (
|
||||
ws syscall.WaitStatus
|
||||
rus syscall.Rusage
|
||||
)
|
||||
flag := syscall.WNOHANG
|
||||
if wait {
|
||||
flag = 0
|
||||
}
|
||||
for {
|
||||
pid, err := syscall.Wait4(-1, &ws, flag, &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()
|
||||
}
|
Loading…
Reference in a new issue