diff --git a/cmd/containerd-shim/main_unix.go b/cmd/containerd-shim/main_unix.go index 8079987..264f3ce 100644 --- a/cmd/containerd-shim/main_unix.go +++ b/cmd/containerd-shim/main_unix.go @@ -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, "") } diff --git a/cmd/containerd/main_unix.go b/cmd/containerd/main_unix.go index 074d095..f45dca9 100644 --- a/cmd/containerd/main_unix.go +++ b/cmd/containerd/main_unix.go @@ -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") } diff --git a/cmd/ctr/run.go b/cmd/ctr/run.go index 2c4d856..95d129d 100644 --- a/cmd/ctr/run.go +++ b/cmd/ctr/run.go @@ -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() diff --git a/sys/epoll.go b/sys/epoll.go index 29ce5b2..13c30c0 100644 --- a/sys/epoll.go +++ b/sys/epoll.go @@ -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) } diff --git a/sys/epoll_arm64.go b/sys/epoll_arm64.go index a56f77e..cc501a5 100644 --- a/sys/epoll_arm64.go +++ b/sys/epoll_arm64.go @@ -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 { diff --git a/sys/prctl.go b/sys/prctl.go index 075c476..63c418d 100644 --- a/sys/prctl.go +++ b/sys/prctl.go @@ -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 diff --git a/sys/reaper.go b/sys/reaper.go index 343cc8f..bbc5a1e 100644 --- a/sys/reaper.go +++ b/sys/reaper.go @@ -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()) } diff --git a/sys/socket_unix.go b/sys/socket_unix.go index e114c55..e5f2ba6 100644 --- a/sys/socket_unix.go +++ b/sys/socket_unix.go @@ -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)