From 4f7d521510573756e9138259f9c0466488f22f3c Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Mon, 10 Apr 2017 11:56:33 -0700 Subject: [PATCH] [exec] Replace syscall with /x/sys/unix This replaces the syscall usage with sys/unix in the execution code Signed-off-by: Michael Crosby --- linux/runtime.go | 8 +++---- linux/shim/client.go | 4 ++-- linux/shim/exec.go | 4 +++- linux/shim/init.go | 4 +++- linux/shim/service.go | 5 ++-- mount_unix.go | 55 ++++++++++++++++++++++--------------------- 6 files changed, 43 insertions(+), 37 deletions(-) diff --git a/linux/runtime.go b/linux/runtime.go index 6ab61e2..625bda7 100644 --- a/linux/runtime.go +++ b/linux/runtime.go @@ -9,7 +9,6 @@ import ( "io/ioutil" "os" "path/filepath" - "syscall" "time" "github.com/containerd/containerd" @@ -21,6 +20,7 @@ import ( runc "github.com/crosbymichael/go-runc" "golang.org/x/net/context" + "golang.org/x/sys/unix" ) const ( @@ -249,9 +249,9 @@ func (r *Runtime) killContainer(ctx context.Context, id string) { // TODO: get Command provided for initial container creation // Command: r.Runtime, LogFormat: runc.JSON, - PdeathSignal: syscall.SIGKILL, + PdeathSignal: unix.SIGKILL, } - if err := runtime.Kill(ctx, id, int(syscall.SIGKILL), &runc.KillOpts{ + if err := runtime.Kill(ctx, id, int(unix.SIGKILL), &runc.KillOpts{ All: true, }); err != nil { log.G(ctx).WithError(err).Warnf("kill all processes for %s", id) @@ -271,7 +271,7 @@ func (r *Runtime) killContainer(ctx context.Context, id string) { log.G(ctx).WithError(err).Warnf("delete container %s", id) } // try to unmount the rootfs is it was not held by an external shim - syscall.Unmount(filepath.Join(r.root, id, "rootfs"), 0) + unix.Unmount(filepath.Join(r.root, id, "rootfs"), 0) // remove container bundle if err := r.deleteBundle(id); err != nil { log.G(ctx).WithError(err).Warnf("delete container bundle %s", id) diff --git a/linux/shim/client.go b/linux/shim/client.go index 07922ed..1c782ed 100644 --- a/linux/shim/client.go +++ b/linux/shim/client.go @@ -2,12 +2,12 @@ package shim import ( "path/filepath" - "syscall" shimapi "github.com/containerd/containerd/api/services/shim" "github.com/containerd/containerd/api/types/container" google_protobuf "github.com/golang/protobuf/ptypes/empty" "golang.org/x/net/context" + "golang.org/x/sys/unix" "google.golang.org/grpc" "google.golang.org/grpc/metadata" ) @@ -68,7 +68,7 @@ func (c *client) Kill(ctx context.Context, in *shimapi.KillRequest, opts ...grpc func (c *client) Exit(ctx context.Context, in *shimapi.ExitRequest, opts ...grpc.CallOption) (*google_protobuf.Empty, error) { // don't exit the calling process for the client // but make sure we unmount the containers rootfs for this client - if err := syscall.Unmount(filepath.Join(c.s.path, "rootfs"), 0); err != nil { + if err := unix.Unmount(filepath.Join(c.s.path, "rootfs"), 0); err != nil { return nil, err } return empty, nil diff --git a/linux/shim/exec.go b/linux/shim/exec.go index 5dc99ca..a50bbaf 100644 --- a/linux/shim/exec.go +++ b/linux/shim/exec.go @@ -12,6 +12,8 @@ import ( "sync" "syscall" + "golang.org/x/sys/unix" + shimapi "github.com/containerd/containerd/api/services/shim" "github.com/crosbymichael/console" runc "github.com/crosbymichael/go-runc" @@ -145,7 +147,7 @@ func (e *execProcess) Resize(ws console.WinSize) error { } func (e *execProcess) Signal(sig int) error { - return syscall.Kill(e.pid, syscall.Signal(sig)) + return unix.Kill(e.pid, syscall.Signal(sig)) } func (e *execProcess) Stdin() io.Closer { diff --git a/linux/shim/init.go b/linux/shim/init.go index 8bcf4ba..021eabc 100644 --- a/linux/shim/init.go +++ b/linux/shim/init.go @@ -10,6 +10,8 @@ import ( "sync" "syscall" + "golang.org/x/sys/unix" + "github.com/containerd/containerd" shimapi "github.com/containerd/containerd/api/services/shim" "github.com/crosbymichael/console" @@ -175,7 +177,7 @@ func (p *initProcess) killAll(context context.Context) error { } func (p *initProcess) Signal(sig int) error { - return syscall.Kill(p.pid, syscall.Signal(sig)) + return unix.Kill(p.pid, syscall.Signal(sig)) } func (p *initProcess) Stdin() io.Closer { diff --git a/linux/shim/service.go b/linux/shim/service.go index cdaa833..8e8902d 100644 --- a/linux/shim/service.go +++ b/linux/shim/service.go @@ -15,6 +15,7 @@ import ( google_protobuf "github.com/golang/protobuf/ptypes/empty" "github.com/pkg/errors" "golang.org/x/net/context" + "golang.org/x/sys/unix" ) var empty = &google_protobuf.Empty{} @@ -180,7 +181,7 @@ func (s *Service) State(ctx context.Context, r *shimapi.StateRequest) (*shimapi. defer s.mu.Unlock() for _, p := range s.processes { status := container.Status_RUNNING - if err := syscall.Kill(p.Pid(), 0); err != nil { + if err := unix.Kill(p.Pid(), 0); err != nil { if err != syscall.ESRCH { return nil, err } @@ -210,7 +211,7 @@ func (s *Service) Resume(ctx context.Context, r *shimapi.ResumeRequest) (*google func (s *Service) Exit(ctx context.Context, r *shimapi.ExitRequest) (*google_protobuf.Empty, error) { // signal ourself to exit - if err := syscall.Kill(os.Getpid(), syscall.SIGTERM); err != nil { + if err := unix.Kill(os.Getpid(), syscall.SIGTERM); err != nil { return nil, err } return empty, nil diff --git a/mount_unix.go b/mount_unix.go index b8f1d5f..8ed4023 100644 --- a/mount_unix.go +++ b/mount_unix.go @@ -4,16 +4,17 @@ package containerd import ( "strings" - "syscall" + + "golang.org/x/sys/unix" ) func (m *Mount) Mount(target string) error { flags, data := parseMountOptions(m.Options) - return syscall.Mount(m.Source, target, m.Type, uintptr(flags), data) + return unix.Mount(m.Source, target, m.Type, uintptr(flags), data) } func Unmount(mount string, flags int) error { - return syscall.Unmount(mount, flags) + return unix.Unmount(mount, flags) } // parseMountOptions takes fstab style mount options and parses them for @@ -27,31 +28,31 @@ func parseMountOptions(options []string) (int, string) { clear bool flag int }{ - "async": {true, syscall.MS_SYNCHRONOUS}, - "atime": {true, syscall.MS_NOATIME}, - "bind": {false, syscall.MS_BIND}, + "async": {true, unix.MS_SYNCHRONOUS}, + "atime": {true, unix.MS_NOATIME}, + "bind": {false, unix.MS_BIND}, "defaults": {false, 0}, - "dev": {true, syscall.MS_NODEV}, - "diratime": {true, syscall.MS_NODIRATIME}, - "dirsync": {false, syscall.MS_DIRSYNC}, - "exec": {true, syscall.MS_NOEXEC}, - "mand": {false, syscall.MS_MANDLOCK}, - "noatime": {false, syscall.MS_NOATIME}, - "nodev": {false, syscall.MS_NODEV}, - "nodiratime": {false, syscall.MS_NODIRATIME}, - "noexec": {false, syscall.MS_NOEXEC}, - "nomand": {true, syscall.MS_MANDLOCK}, - "norelatime": {true, syscall.MS_RELATIME}, - "nostrictatime": {true, syscall.MS_STRICTATIME}, - "nosuid": {false, syscall.MS_NOSUID}, - "rbind": {false, syscall.MS_BIND | syscall.MS_REC}, - "relatime": {false, syscall.MS_RELATIME}, - "remount": {false, syscall.MS_REMOUNT}, - "ro": {false, syscall.MS_RDONLY}, - "rw": {true, syscall.MS_RDONLY}, - "strictatime": {false, syscall.MS_STRICTATIME}, - "suid": {true, syscall.MS_NOSUID}, - "sync": {false, syscall.MS_SYNCHRONOUS}, + "dev": {true, unix.MS_NODEV}, + "diratime": {true, unix.MS_NODIRATIME}, + "dirsync": {false, unix.MS_DIRSYNC}, + "exec": {true, unix.MS_NOEXEC}, + "mand": {false, unix.MS_MANDLOCK}, + "noatime": {false, unix.MS_NOATIME}, + "nodev": {false, unix.MS_NODEV}, + "nodiratime": {false, unix.MS_NODIRATIME}, + "noexec": {false, unix.MS_NOEXEC}, + "nomand": {true, unix.MS_MANDLOCK}, + "norelatime": {true, unix.MS_RELATIME}, + "nostrictatime": {true, unix.MS_STRICTATIME}, + "nosuid": {false, unix.MS_NOSUID}, + "rbind": {false, unix.MS_BIND | unix.MS_REC}, + "relatime": {false, unix.MS_RELATIME}, + "remount": {false, unix.MS_REMOUNT}, + "ro": {false, unix.MS_RDONLY}, + "rw": {true, unix.MS_RDONLY}, + "strictatime": {false, unix.MS_STRICTATIME}, + "suid": {true, unix.MS_NOSUID}, + "sync": {false, unix.MS_SYNCHRONOUS}, } for _, o := range options { // If the option does not exist in the flags table or the flag