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

This replaces the syscall usage with sys/unix in the execution code

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby 2017-04-10 11:56:33 -07:00
parent 4f33aa2b5c
commit 4f7d521510
6 changed files with 43 additions and 37 deletions

View File

@ -9,7 +9,6 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"syscall"
"time" "time"
"github.com/containerd/containerd" "github.com/containerd/containerd"
@ -21,6 +20,7 @@ import (
runc "github.com/crosbymichael/go-runc" runc "github.com/crosbymichael/go-runc"
"golang.org/x/net/context" "golang.org/x/net/context"
"golang.org/x/sys/unix"
) )
const ( const (
@ -249,9 +249,9 @@ func (r *Runtime) killContainer(ctx context.Context, id string) {
// TODO: get Command provided for initial container creation // TODO: get Command provided for initial container creation
// Command: r.Runtime, // Command: r.Runtime,
LogFormat: runc.JSON, 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, All: true,
}); err != nil { }); err != nil {
log.G(ctx).WithError(err).Warnf("kill all processes for %s", id) 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) log.G(ctx).WithError(err).Warnf("delete container %s", id)
} }
// try to unmount the rootfs is it was not held by an external shim // 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 // remove container bundle
if err := r.deleteBundle(id); err != nil { if err := r.deleteBundle(id); err != nil {
log.G(ctx).WithError(err).Warnf("delete container bundle %s", id) log.G(ctx).WithError(err).Warnf("delete container bundle %s", id)

View File

@ -2,12 +2,12 @@ package shim
import ( import (
"path/filepath" "path/filepath"
"syscall"
shimapi "github.com/containerd/containerd/api/services/shim" shimapi "github.com/containerd/containerd/api/services/shim"
"github.com/containerd/containerd/api/types/container" "github.com/containerd/containerd/api/types/container"
google_protobuf "github.com/golang/protobuf/ptypes/empty" google_protobuf "github.com/golang/protobuf/ptypes/empty"
"golang.org/x/net/context" "golang.org/x/net/context"
"golang.org/x/sys/unix"
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/metadata" "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) { 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 // don't exit the calling process for the client
// but make sure we unmount the containers rootfs for this 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 nil, err
} }
return empty, nil return empty, nil

View File

@ -12,6 +12,8 @@ import (
"sync" "sync"
"syscall" "syscall"
"golang.org/x/sys/unix"
shimapi "github.com/containerd/containerd/api/services/shim" shimapi "github.com/containerd/containerd/api/services/shim"
"github.com/crosbymichael/console" "github.com/crosbymichael/console"
runc "github.com/crosbymichael/go-runc" 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 { 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 { func (e *execProcess) Stdin() io.Closer {

View File

@ -10,6 +10,8 @@ import (
"sync" "sync"
"syscall" "syscall"
"golang.org/x/sys/unix"
"github.com/containerd/containerd" "github.com/containerd/containerd"
shimapi "github.com/containerd/containerd/api/services/shim" shimapi "github.com/containerd/containerd/api/services/shim"
"github.com/crosbymichael/console" "github.com/crosbymichael/console"
@ -175,7 +177,7 @@ func (p *initProcess) killAll(context context.Context) error {
} }
func (p *initProcess) Signal(sig int) 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 { func (p *initProcess) Stdin() io.Closer {

View File

@ -15,6 +15,7 @@ import (
google_protobuf "github.com/golang/protobuf/ptypes/empty" google_protobuf "github.com/golang/protobuf/ptypes/empty"
"github.com/pkg/errors" "github.com/pkg/errors"
"golang.org/x/net/context" "golang.org/x/net/context"
"golang.org/x/sys/unix"
) )
var empty = &google_protobuf.Empty{} var empty = &google_protobuf.Empty{}
@ -180,7 +181,7 @@ func (s *Service) State(ctx context.Context, r *shimapi.StateRequest) (*shimapi.
defer s.mu.Unlock() defer s.mu.Unlock()
for _, p := range s.processes { for _, p := range s.processes {
status := container.Status_RUNNING 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 { if err != syscall.ESRCH {
return nil, err 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) { func (s *Service) Exit(ctx context.Context, r *shimapi.ExitRequest) (*google_protobuf.Empty, error) {
// signal ourself to exit // 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 nil, err
} }
return empty, nil return empty, nil

View File

@ -4,16 +4,17 @@ package containerd
import ( import (
"strings" "strings"
"syscall"
"golang.org/x/sys/unix"
) )
func (m *Mount) Mount(target string) error { func (m *Mount) Mount(target string) error {
flags, data := parseMountOptions(m.Options) 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 { 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 // parseMountOptions takes fstab style mount options and parses them for
@ -27,31 +28,31 @@ func parseMountOptions(options []string) (int, string) {
clear bool clear bool
flag int flag int
}{ }{
"async": {true, syscall.MS_SYNCHRONOUS}, "async": {true, unix.MS_SYNCHRONOUS},
"atime": {true, syscall.MS_NOATIME}, "atime": {true, unix.MS_NOATIME},
"bind": {false, syscall.MS_BIND}, "bind": {false, unix.MS_BIND},
"defaults": {false, 0}, "defaults": {false, 0},
"dev": {true, syscall.MS_NODEV}, "dev": {true, unix.MS_NODEV},
"diratime": {true, syscall.MS_NODIRATIME}, "diratime": {true, unix.MS_NODIRATIME},
"dirsync": {false, syscall.MS_DIRSYNC}, "dirsync": {false, unix.MS_DIRSYNC},
"exec": {true, syscall.MS_NOEXEC}, "exec": {true, unix.MS_NOEXEC},
"mand": {false, syscall.MS_MANDLOCK}, "mand": {false, unix.MS_MANDLOCK},
"noatime": {false, syscall.MS_NOATIME}, "noatime": {false, unix.MS_NOATIME},
"nodev": {false, syscall.MS_NODEV}, "nodev": {false, unix.MS_NODEV},
"nodiratime": {false, syscall.MS_NODIRATIME}, "nodiratime": {false, unix.MS_NODIRATIME},
"noexec": {false, syscall.MS_NOEXEC}, "noexec": {false, unix.MS_NOEXEC},
"nomand": {true, syscall.MS_MANDLOCK}, "nomand": {true, unix.MS_MANDLOCK},
"norelatime": {true, syscall.MS_RELATIME}, "norelatime": {true, unix.MS_RELATIME},
"nostrictatime": {true, syscall.MS_STRICTATIME}, "nostrictatime": {true, unix.MS_STRICTATIME},
"nosuid": {false, syscall.MS_NOSUID}, "nosuid": {false, unix.MS_NOSUID},
"rbind": {false, syscall.MS_BIND | syscall.MS_REC}, "rbind": {false, unix.MS_BIND | unix.MS_REC},
"relatime": {false, syscall.MS_RELATIME}, "relatime": {false, unix.MS_RELATIME},
"remount": {false, syscall.MS_REMOUNT}, "remount": {false, unix.MS_REMOUNT},
"ro": {false, syscall.MS_RDONLY}, "ro": {false, unix.MS_RDONLY},
"rw": {true, syscall.MS_RDONLY}, "rw": {true, unix.MS_RDONLY},
"strictatime": {false, syscall.MS_STRICTATIME}, "strictatime": {false, unix.MS_STRICTATIME},
"suid": {true, syscall.MS_NOSUID}, "suid": {true, unix.MS_NOSUID},
"sync": {false, syscall.MS_SYNCHRONOUS}, "sync": {false, unix.MS_SYNCHRONOUS},
} }
for _, o := range options { for _, o := range options {
// If the option does not exist in the flags table or the flag // If the option does not exist in the flags table or the flag