[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"
"os/signal" "os/signal"
"strings" "strings"
"syscall"
"golang.org/x/sys/unix"
"google.golang.org/grpc" "google.golang.org/grpc"
@ -117,11 +118,11 @@ func handleSignals(signals chan os.Signal, server *grpc.Server) error {
for s := range signals { for s := range signals {
logrus.WithField("signal", s).Debug("received signal") logrus.WithField("signal", s).Debug("received signal")
switch s { switch s {
case syscall.SIGCHLD: case unix.SIGCHLD:
if err := reaper.Reap(); err != nil { if err := reaper.Reap(); err != nil {
logrus.WithError(err).Error("reap exit status") 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? // TODO: should we forward signals to the processes if they are still running?
// i.e. machine reboot // i.e. machine reboot
server.Stop() 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 // setupRoot sets up the root as the shim is started in its own mount namespace
func setupRoot() error { 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 ( import (
"os" "os"
"syscall"
"golang.org/x/sys/unix"
"github.com/containerd/containerd/log" "github.com/containerd/containerd/log"
"github.com/containerd/containerd/reaper" "github.com/containerd/containerd/reaper"
@ -18,7 +19,7 @@ const (
) )
var ( 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 { func platformInit(context *cli.Context) error {
@ -35,7 +36,7 @@ func handleSignals(signals chan os.Signal, server *grpc.Server) error {
for s := range signals { for s := range signals {
log.G(global).WithField("signal", s).Debug("received signal") log.G(global).WithField("signal", s).Debug("received signal")
switch s { switch s {
case syscall.SIGCHLD: case unix.SIGCHLD:
if err := reaper.Reap(); err != nil { if err := reaper.Reap(); err != nil {
log.G(global).WithError(err).Error("reap containerd processes") log.G(global).WithError(err).Error("reap containerd processes")
} }

View file

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

View file

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

View file

@ -36,8 +36,9 @@ import "C"
import ( import (
"fmt" "fmt"
"syscall"
"unsafe" "unsafe"
"golang.org/x/sys/unix"
) )
// EpollCreate1 calls a C implementation // EpollCreate1 calls a C implementation
@ -50,8 +51,8 @@ func EpollCreate1(flag int) (int, error) {
} }
// EpollCtl calls a C implementation // EpollCtl calls a C implementation
func EpollCtl(epfd int, op int, fd int, event *syscall.EpollEvent) error { func EpollCtl(epfd int, op int, fd int, event *unix.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)) 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 { if errno < 0 {
return fmt.Errorf("Failed to ctl epoll") 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 // 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 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)))) n := int(C.run_epoll_wait(C.int(epfd), (*C.struct_event_t)(unsafe.Pointer(&c_events))))
if n < 0 { if n < 0 {

View file

@ -6,8 +6,9 @@
package sys package sys
import ( import (
"syscall"
"unsafe" "unsafe"
"golang.org/x/sys/unix"
) )
// PR_SET_CHILD_SUBREAPER allows setting the child subreaper. // 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 // GetSubreaper returns the subreaper setting for the calling process
func GetSubreaper() (int, error) { func GetSubreaper() (int, error) {
var i uintptr 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 -1, err
} }
return int(i), nil 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 // SetSubreaper sets the value i as the subreaper setting for the calling process
func SetSubreaper(i int) error { 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 err
} }
return nil return nil

View file

@ -2,7 +2,7 @@
package sys package sys
import "syscall" import "golang.org/x/sys/unix"
// Exit is the wait4 information from an exited process // Exit is the wait4 information from an exited process
type Exit struct { type Exit struct {
@ -14,17 +14,17 @@ type Exit struct {
// exit information // exit information
func Reap(wait bool) (exits []Exit, err error) { func Reap(wait bool) (exits []Exit, err error) {
var ( var (
ws syscall.WaitStatus ws unix.WaitStatus
rus syscall.Rusage rus unix.Rusage
) )
flag := syscall.WNOHANG flag := unix.WNOHANG
if wait { if wait {
flag = 0 flag = 0
} }
for { for {
pid, err := syscall.Wait4(-1, &ws, flag, &rus) pid, err := unix.Wait4(-1, &ws, flag, &rus)
if err != nil { if err != nil {
if err == syscall.ECHILD { if err == unix.ECHILD {
return exits, nil return exits, nil
} }
return exits, err return exits, err
@ -43,7 +43,7 @@ const exitSignalOffset = 128
// exitStatus returns the correct exit status for a process based on if it // exitStatus returns the correct exit status for a process based on if it
// was signaled or exited cleanly // was signaled or exited cleanly
func exitStatus(status syscall.WaitStatus) int { func exitStatus(status unix.WaitStatus) int {
if status.Signaled() { if status.Signaled() {
return exitSignalOffset + int(status.Signal()) return exitSignalOffset + int(status.Signal())
} }

View file

@ -6,7 +6,8 @@ import (
"net" "net"
"os" "os"
"path/filepath" "path/filepath"
"syscall"
"golang.org/x/sys/unix"
) )
// CreateUnixSocket creates a unix socket and returns the listener // 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 { if err := os.MkdirAll(filepath.Dir(path), 0660); err != nil {
return nil, err 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 nil, err
} }
return net.Listen("unix", path) return net.Listen("unix", path)