[bin] Replace syscall with /x/sys/unix

Replace syscall usage with /sys/unix in the binaries and their packages

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby 2017-04-10 12:01:33 -07:00
parent 4f7d521510
commit 3db1ea8d07
8 changed files with 40 additions and 36 deletions

View file

@ -8,7 +8,8 @@ import (
"os"
"os/signal"
"strings"
"syscall"
"golang.org/x/sys/unix"
"google.golang.org/grpc"
@ -117,11 +118,11 @@ func handleSignals(signals chan os.Signal, server *grpc.Server) error {
for s := range signals {
logrus.WithField("signal", s).Debug("received signal")
switch s {
case syscall.SIGCHLD:
case unix.SIGCHLD:
if err := reaper.Reap(); err != nil {
logrus.WithError(err).Error("reap exit status")
}
case syscall.SIGTERM, syscall.SIGINT:
case unix.SIGTERM, unix.SIGINT:
// TODO: should we forward signals to the processes if they are still running?
// i.e. machine reboot
server.Stop()
@ -133,5 +134,5 @@ func handleSignals(signals chan os.Signal, server *grpc.Server) error {
// setupRoot sets up the root as the shim is started in its own mount namespace
func setupRoot() error {
return syscall.Mount("", "/", "", syscall.MS_SLAVE|syscall.MS_REC, "")
return unix.Mount("", "/", "", unix.MS_SLAVE|unix.MS_REC, "")
}

View file

@ -4,7 +4,8 @@ package main
import (
"os"
"syscall"
"golang.org/x/sys/unix"
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/reaper"
@ -18,7 +19,7 @@ const (
)
var (
handledSignals = []os.Signal{syscall.SIGTERM, syscall.SIGINT, syscall.SIGUSR1, syscall.SIGCHLD}
handledSignals = []os.Signal{unix.SIGTERM, unix.SIGINT, unix.SIGUSR1, unix.SIGCHLD}
)
func platformInit(context *cli.Context) error {
@ -35,7 +36,7 @@ func handleSignals(signals chan os.Signal, server *grpc.Server) error {
for s := range signals {
log.G(global).WithField("signal", s).Debug("received signal")
switch s {
case syscall.SIGCHLD:
case unix.SIGCHLD:
if err := reaper.Reap(); err != nil {
log.G(global).WithError(err).Error("reap containerd processes")
}

View file

@ -7,7 +7,8 @@ import (
"os"
"os/signal"
"runtime"
"syscall"
"golang.org/x/sys/unix"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
@ -207,7 +208,7 @@ func handleConsoleResize(ctx gocontext.Context, service execution.ContainerServi
return err
}
s := make(chan os.Signal, 16)
signal.Notify(s, syscall.SIGWINCH)
signal.Notify(s, unix.SIGWINCH)
go func() {
for range s {
size, err := con.Size()

View file

@ -2,21 +2,19 @@
package sys
import (
"syscall"
)
import "golang.org/x/sys/unix"
// EpollCreate1 directly calls syscall.EpollCreate1
// EpollCreate1 directly calls unix.EpollCreate1
func EpollCreate1(flag int) (int, error) {
return syscall.EpollCreate1(flag)
return unix.EpollCreate1(flag)
}
// EpollCtl directly calls syscall.EpollCtl
func EpollCtl(epfd int, op int, fd int, event *syscall.EpollEvent) error {
return syscall.EpollCtl(epfd, op, fd, event)
// EpollCtl directly calls unix.EpollCtl
func EpollCtl(epfd int, op int, fd int, event *unix.EpollEvent) error {
return unix.EpollCtl(epfd, op, fd, event)
}
// EpollWait directly calls syscall.EpollWait
func EpollWait(epfd int, events []syscall.EpollEvent, msec int) (int, error) {
return syscall.EpollWait(epfd, events, msec)
// EpollWait directly calls unix.EpollWait
func EpollWait(epfd int, events []unix.EpollEvent, msec int) (int, error) {
return unix.EpollWait(epfd, events, msec)
}

View file

@ -36,8 +36,9 @@ import "C"
import (
"fmt"
"syscall"
"unsafe"
"golang.org/x/sys/unix"
)
// EpollCreate1 calls a C implementation
@ -50,8 +51,8 @@ func EpollCreate1(flag int) (int, error) {
}
// EpollCtl calls a C implementation
func EpollCtl(epfd int, op int, fd int, event *syscall.EpollEvent) error {
errno := C.EpollCtl(C.int(epfd), C.int(syscall.EPOLL_CTL_ADD), C.int(fd), C.int(event.Events), C.int(event.Fd))
func EpollCtl(epfd int, op int, fd int, event *unix.EpollEvent) error {
errno := C.EpollCtl(C.int(epfd), C.int(unix.EPOLL_CTL_ADD), C.int(fd), C.int(event.Events), C.int(event.Fd))
if errno < 0 {
return fmt.Errorf("Failed to ctl epoll")
}
@ -59,7 +60,7 @@ func EpollCtl(epfd int, op int, fd int, event *syscall.EpollEvent) error {
}
// EpollWait calls a C implementation
func EpollWait(epfd int, events []syscall.EpollEvent, msec int) (int, error) {
func EpollWait(epfd int, events []unix.EpollEvent, msec int) (int, error) {
var c_events [128]C.struct_event_t
n := int(C.run_epoll_wait(C.int(epfd), (*C.struct_event_t)(unsafe.Pointer(&c_events))))
if n < 0 {

View file

@ -6,8 +6,9 @@
package sys
import (
"syscall"
"unsafe"
"golang.org/x/sys/unix"
)
// PR_SET_CHILD_SUBREAPER allows setting the child subreaper.
@ -33,7 +34,7 @@ const prGetChildSubreaper = 37
// GetSubreaper returns the subreaper setting for the calling process
func GetSubreaper() (int, error) {
var i uintptr
if _, _, err := syscall.RawSyscall(syscall.SYS_PRCTL, prGetChildSubreaper, uintptr(unsafe.Pointer(&i)), 0); err != 0 {
if _, _, err := unix.RawSyscall(unix.SYS_PRCTL, prGetChildSubreaper, uintptr(unsafe.Pointer(&i)), 0); err != 0 {
return -1, err
}
return int(i), nil
@ -41,7 +42,7 @@ func GetSubreaper() (int, error) {
// 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, prSetChildSubreaper, uintptr(i), 0); err != 0 {
if _, _, err := unix.RawSyscall(unix.SYS_PRCTL, prSetChildSubreaper, uintptr(i), 0); err != 0 {
return err
}
return nil

View file

@ -2,7 +2,7 @@
package sys
import "syscall"
import "golang.org/x/sys/unix"
// Exit is the wait4 information from an exited process
type Exit struct {
@ -14,17 +14,17 @@ type Exit struct {
// exit information
func Reap(wait bool) (exits []Exit, err error) {
var (
ws syscall.WaitStatus
rus syscall.Rusage
ws unix.WaitStatus
rus unix.Rusage
)
flag := syscall.WNOHANG
flag := unix.WNOHANG
if wait {
flag = 0
}
for {
pid, err := syscall.Wait4(-1, &ws, flag, &rus)
pid, err := unix.Wait4(-1, &ws, flag, &rus)
if err != nil {
if err == syscall.ECHILD {
if err == unix.ECHILD {
return exits, nil
}
return exits, err
@ -43,7 +43,7 @@ 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 {
func exitStatus(status unix.WaitStatus) int {
if status.Signaled() {
return exitSignalOffset + int(status.Signal())
}

View file

@ -6,7 +6,8 @@ import (
"net"
"os"
"path/filepath"
"syscall"
"golang.org/x/sys/unix"
)
// CreateUnixSocket creates a unix socket and returns the listener
@ -14,7 +15,7 @@ func CreateUnixSocket(path string) (net.Listener, error) {
if err := os.MkdirAll(filepath.Dir(path), 0660); err != nil {
return nil, err
}
if err := syscall.Unlink(path); err != nil && !os.IsNotExist(err) {
if err := unix.Unlink(path); err != nil && !os.IsNotExist(err) {
return nil, err
}
return net.Listen("unix", path)