[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"
"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)

View File

@ -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

View File

@ -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 {

View File

@ -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 {

View File

@ -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

View File

@ -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