Merge pull request #2325 from kolyshkin/nits-2

Nits
This commit is contained in:
Akihiro Suda 2020-04-20 01:43:15 +09:00 committed by GitHub
commit cd5f4fd93c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 19 additions and 38 deletions

View File

@ -6,7 +6,6 @@ import (
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
"syscall"
"time" "time"
"github.com/opencontainers/runc/libcontainer" "github.com/opencontainers/runc/libcontainer"
@ -19,7 +18,7 @@ func killContainer(container libcontainer.Container) error {
_ = container.Signal(unix.SIGKILL, false) _ = container.Signal(unix.SIGKILL, false)
for i := 0; i < 100; i++ { for i := 0; i < 100; i++ {
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
if err := container.Signal(syscall.Signal(0), false); err != nil { if err := container.Signal(unix.Signal(0), false); err != nil {
destroy(container) destroy(container)
return nil return nil
} }

View File

@ -6,7 +6,6 @@ import (
"fmt" "fmt"
"strconv" "strconv"
"strings" "strings"
"syscall"
"github.com/urfave/cli" "github.com/urfave/cli"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
@ -23,7 +22,7 @@ Where "<container-id>" is the name for the instance of the container and
EXAMPLE: EXAMPLE:
For example, if the container id is "ubuntu01" the following will send a "KILL" For example, if the container id is "ubuntu01" the following will send a "KILL"
signal to the init process of the "ubuntu01" container: signal to the init process of the "ubuntu01" container:
# runc kill ubuntu01 KILL`, # runc kill ubuntu01 KILL`,
Flags: []cli.Flag{ Flags: []cli.Flag{
cli.BoolFlag{ cli.BoolFlag{
@ -56,10 +55,10 @@ signal to the init process of the "ubuntu01" container:
}, },
} }
func parseSignal(rawSignal string) (syscall.Signal, error) { func parseSignal(rawSignal string) (unix.Signal, error) {
s, err := strconv.Atoi(rawSignal) s, err := strconv.Atoi(rawSignal)
if err == nil { if err == nil {
return syscall.Signal(s), nil return unix.Signal(s), nil
} }
sig := strings.ToUpper(rawSignal) sig := strings.ToUpper(rawSignal)
if !strings.HasPrefix(sig, "SIG") { if !strings.HasPrefix(sig, "SIG") {

View File

@ -8,7 +8,6 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"sync" "sync"
"syscall"
"github.com/opencontainers/runc/libcontainer/cgroups" "github.com/opencontainers/runc/libcontainer/cgroups"
"github.com/opencontainers/runc/libcontainer/configs" "github.com/opencontainers/runc/libcontainer/configs"
@ -118,7 +117,7 @@ func isIgnorableError(rootless bool, err error) bool {
return true return true
} }
// Handle some specific syscall errors. // Handle some specific syscall errors.
var errno syscall.Errno var errno unix.Errno
if errors.As(err, &errno) { if errors.As(err, &errno) {
return errno == unix.EROFS || errno == unix.EPERM || errno == unix.EACCES return errno == unix.EROFS || errno == unix.EPERM || errno == unix.EACCES
} }

View File

@ -5,11 +5,11 @@ package fscommon
import ( import (
"io/ioutil" "io/ioutil"
"os" "os"
"syscall"
securejoin "github.com/cyphar/filepath-securejoin" securejoin "github.com/cyphar/filepath-securejoin"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
) )
func WriteFile(dir, file, data string) error { func WriteFile(dir, file, data string) error {
@ -41,20 +41,10 @@ func ReadFile(dir, file string) (string, error) {
func retryingWriteFile(filename string, data []byte, perm os.FileMode) error { func retryingWriteFile(filename string, data []byte, perm os.FileMode) error {
for { for {
err := ioutil.WriteFile(filename, data, perm) err := ioutil.WriteFile(filename, data, perm)
if isInterruptedWriteFile(err) { if errors.Is(err, unix.EINTR) {
logrus.Infof("interrupted while writing %s to %s", string(data), filename) logrus.Infof("interrupted while writing %s to %s", string(data), filename)
continue continue
} }
return err return err
} }
} }
func isInterruptedWriteFile(err error) bool {
if patherr, ok := err.(*os.PathError); ok {
errno, ok2 := patherr.Err.(syscall.Errno)
if ok2 && errno == syscall.EINTR {
return true
}
}
return false
}

View File

@ -16,7 +16,6 @@ import (
"reflect" "reflect"
"strings" "strings"
"sync" "sync"
"syscall" // only for SysProcAttr and Signal
"time" "time"
securejoin "github.com/cyphar/filepath-securejoin" securejoin "github.com/cyphar/filepath-securejoin"
@ -309,7 +308,7 @@ func awaitFifoOpen(path string) <-chan openResult {
func fifoOpen(path string, block bool) openResult { func fifoOpen(path string, block bool) openResult {
flags := os.O_RDONLY flags := os.O_RDONLY
if !block { if !block {
flags |= syscall.O_NONBLOCK flags |= unix.O_NONBLOCK
} }
f, err := os.OpenFile(path, flags, 0) f, err := os.OpenFile(path, flags, 0)
if err != nil { if err != nil {
@ -480,7 +479,7 @@ func (c *linuxContainer) commandTemplate(p *Process, childInitPipe *os.File, chi
cmd.Stderr = p.Stderr cmd.Stderr = p.Stderr
cmd.Dir = c.config.Rootfs cmd.Dir = c.config.Rootfs
if cmd.SysProcAttr == nil { if cmd.SysProcAttr == nil {
cmd.SysProcAttr = &syscall.SysProcAttr{} cmd.SysProcAttr = &unix.SysProcAttr{}
} }
cmd.Env = append(cmd.Env, fmt.Sprintf("GOMAXPROCS=%s", os.Getenv("GOMAXPROCS"))) cmd.Env = append(cmd.Env, fmt.Sprintf("GOMAXPROCS=%s", os.Getenv("GOMAXPROCS")))
cmd.ExtraFiles = append(cmd.ExtraFiles, p.ExtraFiles...) cmd.ExtraFiles = append(cmd.ExtraFiles, p.ExtraFiles...)
@ -506,7 +505,7 @@ func (c *linuxContainer) commandTemplate(p *Process, childInitPipe *os.File, chi
// PID1 the pdeathsig is being delivered to the container's init process by the kernel for some reason // PID1 the pdeathsig is being delivered to the container's init process by the kernel for some reason
// even with the parent still running. // even with the parent still running.
if c.config.ParentDeathSignal > 0 { if c.config.ParentDeathSignal > 0 {
cmd.SysProcAttr.Pdeathsig = syscall.Signal(c.config.ParentDeathSignal) cmd.SysProcAttr.Pdeathsig = unix.Signal(c.config.ParentDeathSignal)
} }
return cmd return cmd
} }
@ -1005,8 +1004,8 @@ func (c *linuxContainer) Checkpoint(criuOpts *CriuOpts) error {
// CRIU expects the information about an external namespace // CRIU expects the information about an external namespace
// like this: --external net[<inode>]:<key> // like this: --external net[<inode>]:<key>
// This <key> is always 'extRootNetNS'. // This <key> is always 'extRootNetNS'.
var netns syscall.Stat_t var netns unix.Stat_t
err = syscall.Stat(nsPath, &netns) err = unix.Stat(nsPath, &netns)
if err != nil { if err != nil {
return err return err
} }
@ -1857,7 +1856,7 @@ func (c *linuxContainer) isPaused() (bool, error) {
data, err := ioutil.ReadFile(filepath.Join(fcg, filename)) data, err := ioutil.ReadFile(filepath.Join(fcg, filename))
if err != nil { if err != nil {
// If freezer cgroup is not mounted, the container would just be not paused. // If freezer cgroup is not mounted, the container would just be not paused.
if os.IsNotExist(err) || errors.Is(err, syscall.ENODEV) { if os.IsNotExist(err) || errors.Is(err, unix.ENODEV) {
return false, nil return false, nil
} }
return false, newSystemErrorWithCause(err, "checking if container is paused") return false, newSystemErrorWithCause(err, "checking if container is paused")

View File

@ -10,7 +10,6 @@ import (
"net" "net"
"os" "os"
"strings" "strings"
"syscall" // only for Errno
"unsafe" "unsafe"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
@ -455,7 +454,7 @@ func isWaitable(pid int) (bool, error) {
// isNoChildren returns true if err represents a unix.ECHILD (formerly syscall.ECHILD) false otherwise // isNoChildren returns true if err represents a unix.ECHILD (formerly syscall.ECHILD) false otherwise
func isNoChildren(err error) bool { func isNoChildren(err error) bool {
switch err := err.(type) { switch err := err.(type) {
case syscall.Errno: case unix.Errno:
if err == unix.ECHILD { if err == unix.ECHILD {
return true return true
} }

View File

@ -11,7 +11,6 @@ import (
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"strconv" "strconv"
"syscall" // only for Signal
"github.com/opencontainers/runc/libcontainer/cgroups" "github.com/opencontainers/runc/libcontainer/cgroups"
"github.com/opencontainers/runc/libcontainer/configs" "github.com/opencontainers/runc/libcontainer/configs"
@ -76,7 +75,7 @@ func (p *setnsProcess) startTime() (uint64, error) {
} }
func (p *setnsProcess) signal(sig os.Signal) error { func (p *setnsProcess) signal(sig os.Signal) error {
s, ok := sig.(syscall.Signal) s, ok := sig.(unix.Signal)
if !ok { if !ok {
return errors.New("os: unsupported signal type") return errors.New("os: unsupported signal type")
} }
@ -506,7 +505,7 @@ func (p *initProcess) createNetworkInterfaces() error {
} }
func (p *initProcess) signal(sig os.Signal) error { func (p *initProcess) signal(sig os.Signal) error {
s, ok := sig.(syscall.Signal) s, ok := sig.(unix.Signal)
if !ok { if !ok {
return errors.New("os: unsupported signal type") return errors.New("os: unsupported signal type")
} }

View File

@ -7,7 +7,6 @@ import (
"os" "os"
"os/exec" "os/exec"
"runtime" "runtime"
"syscall" //only for Exec
"github.com/opencontainers/runc/libcontainer/apparmor" "github.com/opencontainers/runc/libcontainer/apparmor"
"github.com/opencontainers/runc/libcontainer/configs" "github.com/opencontainers/runc/libcontainer/configs"
@ -207,7 +206,7 @@ func (l *linuxStandardInit) Init() error {
return newSystemErrorWithCause(err, "init seccomp") return newSystemErrorWithCause(err, "init seccomp")
} }
} }
if err := syscall.Exec(name, l.config.Args[0:], os.Environ()); err != nil { if err := unix.Exec(name, l.config.Args[0:], os.Environ()); err != nil {
return newSystemErrorWithCause(err, "exec user process") return newSystemErrorWithCause(err, "exec user process")
} }
return nil return nil

View File

@ -5,7 +5,6 @@ package system
import ( import (
"os" "os"
"os/exec" "os/exec"
"syscall" // only for exec
"unsafe" "unsafe"
"github.com/opencontainers/runc/libcontainer/user" "github.com/opencontainers/runc/libcontainer/user"
@ -51,7 +50,7 @@ func Execv(cmd string, args []string, env []string) error {
return err return err
} }
return syscall.Exec(name, args, env) return unix.Exec(name, args, env)
} }
func Prlimit(pid, resource int, limit unix.Rlimit) error { func Prlimit(pid, resource int, limit unix.Rlimit) error {

View File

@ -5,7 +5,6 @@ package main
import ( import (
"os" "os"
"os/signal" "os/signal"
"syscall" // only for Signal
"github.com/opencontainers/runc/libcontainer" "github.com/opencontainers/runc/libcontainer"
"github.com/opencontainers/runc/libcontainer/system" "github.com/opencontainers/runc/libcontainer/system"
@ -103,7 +102,7 @@ func (h *signalHandler) forward(process *libcontainer.Process, tty *tty, detach
} }
default: default:
logrus.Debugf("sending signal to process %s", s) logrus.Debugf("sending signal to process %s", s)
if err := unix.Kill(pid1, s.(syscall.Signal)); err != nil { if err := unix.Kill(pid1, s.(unix.Signal)); err != nil {
logrus.Error(err) logrus.Error(err)
} }
} }