mirror of https://github.com/k3s-io/k3s
switch from package syscall to x/sys/unix
The syscall package is locked down and the comment in [1] advises to switch code to use the corresponding package from golang.org/x/sys. Do so and replace usage of package syscall with package golang.org/x/sys/unix where applicable. [1] https://github.com/golang/go/blob/master/src/syscall/syscall.go#L21-L24 This will also allow to get updates and fixes for syscall wrappers without having to use a new go version. Errno, Signal and SysProcAttr aren't changed as they haven't been implemented in /x/sys/. Stat_t from syscall is used if standard library packages (e.g. os) require it. syscall.SIGTERM is used for cross-platform files.pull/6/head
parent
1fd18181ab
commit
4a69005fa1
|
@ -14,6 +14,7 @@ go_library(
|
|||
tags = ["automanaged"],
|
||||
visibility = ["//build/visible_to:pkg_kubectl_util_CONSUMERS"],
|
||||
deps = [
|
||||
"//vendor/golang.org/x/sys/unix:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||
],
|
||||
|
|
|
@ -21,6 +21,7 @@ go_library(
|
|||
"//pkg/util/interrupt:go_default_library",
|
||||
"//vendor/github.com/docker/docker/pkg/term:go_default_library",
|
||||
"//vendor/github.com/mitchellh/go-wordwrap:go_default_library",
|
||||
"//vendor/golang.org/x/sys/unix:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/util/runtime:go_default_library",
|
||||
"//vendor/k8s.io/client-go/tools/remotecommand:go_default_library",
|
||||
],
|
||||
|
|
|
@ -21,8 +21,8 @@ package term
|
|||
import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
"k8s.io/apimachinery/pkg/util/runtime"
|
||||
"k8s.io/client-go/tools/remotecommand"
|
||||
)
|
||||
|
@ -35,7 +35,7 @@ func monitorResizeEvents(fd uintptr, resizeEvents chan<- remotecommand.TerminalS
|
|||
defer runtime.HandleCrash()
|
||||
|
||||
winch := make(chan os.Signal, 1)
|
||||
signal.Notify(winch, syscall.SIGWINCH)
|
||||
signal.Notify(winch, unix.SIGWINCH)
|
||||
defer signal.Stop(winch)
|
||||
|
||||
for {
|
||||
|
|
|
@ -19,9 +19,9 @@ limitations under the License.
|
|||
package util
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
func Umask(mask int) (old int, err error) {
|
||||
return syscall.Umask(mask), nil
|
||||
return unix.Umask(mask), nil
|
||||
}
|
||||
|
|
|
@ -72,6 +72,7 @@ go_library(
|
|||
"//pkg/kubelet/util/format:go_default_library",
|
||||
"//pkg/quota/evaluator/core:go_default_library",
|
||||
"//vendor/github.com/golang/glog:go_default_library",
|
||||
"//vendor/golang.org/x/sys/unix:go_default_library",
|
||||
"//vendor/k8s.io/api/core/v1:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/api/resource:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
|
|
|
@ -25,9 +25,9 @@ import "C"
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"syscall"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
type memcgThresholdNotifier struct {
|
||||
|
@ -43,22 +43,22 @@ var _ ThresholdNotifier = &memcgThresholdNotifier{}
|
|||
// NewMemCGThresholdNotifier sends notifications when a cgroup threshold
|
||||
// is crossed (in either direction) for a given cgroup attribute
|
||||
func NewMemCGThresholdNotifier(path, attribute, threshold, description string, handler thresholdNotifierHandlerFunc) (ThresholdNotifier, error) {
|
||||
watchfd, err := syscall.Open(fmt.Sprintf("%s/%s", path, attribute), syscall.O_RDONLY, 0)
|
||||
watchfd, err := unix.Open(fmt.Sprintf("%s/%s", path, attribute), unix.O_RDONLY, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
syscall.Close(watchfd)
|
||||
unix.Close(watchfd)
|
||||
}
|
||||
}()
|
||||
controlfd, err := syscall.Open(fmt.Sprintf("%s/cgroup.event_control", path), syscall.O_WRONLY, 0)
|
||||
controlfd, err := unix.Open(fmt.Sprintf("%s/cgroup.event_control", path), unix.O_WRONLY, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
syscall.Close(controlfd)
|
||||
unix.Close(controlfd)
|
||||
}
|
||||
}()
|
||||
efd, err := C.eventfd(0, C.EFD_CLOEXEC)
|
||||
|
@ -72,12 +72,12 @@ func NewMemCGThresholdNotifier(path, attribute, threshold, description string, h
|
|||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
syscall.Close(eventfd)
|
||||
unix.Close(eventfd)
|
||||
}
|
||||
}()
|
||||
glog.V(2).Infof("eviction: setting notification threshold to %s", threshold)
|
||||
config := fmt.Sprintf("%d %d %s", eventfd, watchfd, threshold)
|
||||
_, err = syscall.Write(controlfd, []byte(config))
|
||||
_, err = unix.Write(controlfd, []byte(config))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ func NewMemCGThresholdNotifier(path, attribute, threshold, description string, h
|
|||
func getThresholdEvents(eventfd int, eventCh chan<- struct{}, stopCh <-chan struct{}) {
|
||||
for {
|
||||
buf := make([]byte, 8)
|
||||
_, err := syscall.Read(eventfd, buf)
|
||||
_, err := unix.Read(eventfd, buf)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -113,9 +113,9 @@ func (n *memcgThresholdNotifier) Start(stopCh <-chan struct{}) {
|
|||
select {
|
||||
case <-stopCh:
|
||||
glog.V(2).Infof("eviction: stopping threshold notifier")
|
||||
syscall.Close(n.watchfd)
|
||||
syscall.Close(n.controlfd)
|
||||
syscall.Close(n.eventfd)
|
||||
unix.Close(n.watchfd)
|
||||
unix.Close(n.controlfd)
|
||||
unix.Close(n.eventfd)
|
||||
return
|
||||
case <-eventCh:
|
||||
glog.V(2).Infof("eviction: threshold crossed")
|
||||
|
|
|
@ -31,6 +31,7 @@ go_library(
|
|||
"//vendor/github.com/containernetworking/cni/pkg/types/020:go_default_library",
|
||||
"//vendor/github.com/golang/glog:go_default_library",
|
||||
"//vendor/github.com/vishvananda/netlink:go_default_library",
|
||||
"//vendor/golang.org/x/sys/unix:go_default_library",
|
||||
"//vendor/k8s.io/api/core/v1:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/util/errors:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/util/net:go_default_library",
|
||||
|
|
|
@ -26,7 +26,6 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/containernetworking/cni/libcni"
|
||||
|
@ -34,6 +33,7 @@ import (
|
|||
cnitypes020 "github.com/containernetworking/cni/pkg/types/020"
|
||||
"github.com/golang/glog"
|
||||
"github.com/vishvananda/netlink"
|
||||
"golang.org/x/sys/unix"
|
||||
"k8s.io/api/core/v1"
|
||||
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
||||
utilnet "k8s.io/apimachinery/pkg/util/net"
|
||||
|
@ -286,7 +286,7 @@ func (plugin *kubenetNetworkPlugin) clearBridgeAddressesExcept(keep *net.IPNet)
|
|||
return
|
||||
}
|
||||
|
||||
addrs, err := netlink.AddrList(bridge, syscall.AF_INET)
|
||||
addrs, err := netlink.AddrList(bridge, unix.AF_INET)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ go_library(
|
|||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//vendor/github.com/golang/glog:go_default_library",
|
||||
"//vendor/golang.org/x/sys/unix:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
],
|
||||
)
|
||||
|
|
|
@ -22,10 +22,10 @@ import (
|
|||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -43,7 +43,7 @@ func CreateListener(endpoint string) (net.Listener, error) {
|
|||
}
|
||||
|
||||
// Unlink to cleanup the previous socket file.
|
||||
err = syscall.Unlink(addr)
|
||||
err = unix.Unlink(addr)
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
return nil, fmt.Errorf("failed to unlink socket file %q: %v", addr, err)
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ go_library(
|
|||
"//pkg/util/iptables:go_default_library",
|
||||
"//pkg/util/slice:go_default_library",
|
||||
"//vendor/github.com/golang/glog:go_default_library",
|
||||
"//vendor/golang.org/x/sys/unix:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/util/errors:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/util/net:go_default_library",
|
||||
|
|
|
@ -18,8 +18,8 @@ limitations under the License.
|
|||
|
||||
package userspace
|
||||
|
||||
import "syscall"
|
||||
import "golang.org/x/sys/unix"
|
||||
|
||||
func setRLimit(limit uint64) error {
|
||||
return syscall.Setrlimit(syscall.RLIMIT_NOFILE, &syscall.Rlimit{Max: limit, Cur: limit})
|
||||
return unix.Setrlimit(unix.RLIMIT_NOFILE, &unix.Rlimit{Max: limit, Cur: limit})
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ go_library(
|
|||
name = "go_default_library",
|
||||
srcs = ["flock_unix.go"],
|
||||
tags = ["automanaged"],
|
||||
deps = ["//vendor/golang.org/x/sys/unix:go_default_library"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
|
|
|
@ -18,12 +18,12 @@ limitations under the License.
|
|||
|
||||
package flock
|
||||
|
||||
import "syscall"
|
||||
import "golang.org/x/sys/unix"
|
||||
|
||||
// Acquire acquires a lock on a file for the duration of the process. This method
|
||||
// is reentrant.
|
||||
func Acquire(path string) error {
|
||||
fd, err := syscall.Open(path, syscall.O_CREAT|syscall.O_RDWR, 0600)
|
||||
fd, err := unix.Open(path, unix.O_CREAT|unix.O_RDWR, 0600)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -31,5 +31,5 @@ func Acquire(path string) error {
|
|||
// We don't need to close the fd since we should hold
|
||||
// it until the process exits.
|
||||
|
||||
return syscall.Flock(fd, syscall.LOCK_EX)
|
||||
return unix.Flock(fd, unix.LOCK_EX)
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ go_library(
|
|||
deps = [
|
||||
"//pkg/util/exec:go_default_library",
|
||||
"//vendor/github.com/golang/glog:go_default_library",
|
||||
"//vendor/golang.org/x/sys/unix:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
|
||||
],
|
||||
)
|
||||
|
|
|
@ -30,6 +30,7 @@ import (
|
|||
"syscall"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"golang.org/x/sys/unix"
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
utilexec "k8s.io/kubernetes/pkg/util/exec"
|
||||
)
|
||||
|
@ -220,14 +221,14 @@ func exclusiveOpenFailsOnDevice(pathname string) (bool, error) {
|
|||
glog.Errorf("Path %q is not refering to a device.", pathname)
|
||||
return false, nil
|
||||
}
|
||||
fd, errno := syscall.Open(pathname, syscall.O_RDONLY|syscall.O_EXCL, 0)
|
||||
fd, errno := unix.Open(pathname, unix.O_RDONLY|unix.O_EXCL, 0)
|
||||
// If the device is in use, open will return an invalid fd.
|
||||
// When this happens, it is expected that Close will fail and throw an error.
|
||||
defer syscall.Close(fd)
|
||||
defer unix.Close(fd)
|
||||
if errno == nil {
|
||||
// device not in use
|
||||
return false, nil
|
||||
} else if errno == syscall.EBUSY {
|
||||
} else if errno == unix.EBUSY {
|
||||
// device is in use
|
||||
return true, nil
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ go_library(
|
|||
name = "go_default_library",
|
||||
srcs = ["rlimit_linux.go"],
|
||||
tags = ["automanaged"],
|
||||
deps = ["//vendor/golang.org/x/sys/unix:go_default_library"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
|
|
|
@ -19,9 +19,9 @@ limitations under the License.
|
|||
package rlimit
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
func RlimitNumFiles(maxOpenFiles uint64) {
|
||||
syscall.Setrlimit(syscall.RLIMIT_NOFILE, &syscall.Rlimit{Max: maxOpenFiles, Cur: maxOpenFiles})
|
||||
unix.Setrlimit(unix.RLIMIT_NOFILE, &unix.Rlimit{Max: maxOpenFiles, Cur: maxOpenFiles})
|
||||
}
|
||||
|
|
|
@ -75,6 +75,7 @@ go_test(
|
|||
deps = [
|
||||
"//pkg/volume:go_default_library",
|
||||
"//pkg/volume/testing:go_default_library",
|
||||
"//vendor/golang.org/x/sys/unix:go_default_library",
|
||||
"//vendor/k8s.io/client-go/util/testing:go_default_library",
|
||||
],
|
||||
)
|
||||
|
|
|
@ -22,6 +22,7 @@ go_library(
|
|||
"//pkg/volume:go_default_library",
|
||||
"//pkg/volume/util:go_default_library",
|
||||
"//vendor/github.com/golang/glog:go_default_library",
|
||||
"//vendor/golang.org/x/sys/unix:go_default_library",
|
||||
"//vendor/k8s.io/api/core/v1:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
|
||||
|
|
|
@ -20,9 +20,9 @@ package empty_dir
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"syscall"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"golang.org/x/sys/unix"
|
||||
"k8s.io/kubernetes/pkg/util/mount"
|
||||
)
|
||||
|
||||
|
@ -40,8 +40,8 @@ func (m *realMountDetector) GetMountMedium(path string) (storageMedium, bool, er
|
|||
if err != nil {
|
||||
return 0, false, fmt.Errorf("IsLikelyNotMountPoint(%q): %v", path, err)
|
||||
}
|
||||
buf := syscall.Statfs_t{}
|
||||
if err := syscall.Statfs(path, &buf); err != nil {
|
||||
buf := unix.Statfs_t{}
|
||||
if err := unix.Statfs(path, &buf); err != nil {
|
||||
return 0, false, fmt.Errorf("statfs(%q): %v", path, err)
|
||||
}
|
||||
|
||||
|
|
|
@ -22,17 +22,17 @@ import (
|
|||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
utiltesting "k8s.io/client-go/util/testing"
|
||||
. "k8s.io/kubernetes/pkg/volume"
|
||||
volumetest "k8s.io/kubernetes/pkg/volume/testing"
|
||||
)
|
||||
|
||||
func getExpectedBlockSize(path string) int64 {
|
||||
statfs := &syscall.Statfs_t{}
|
||||
err := syscall.Statfs(path, statfs)
|
||||
statfs := &unix.Statfs_t{}
|
||||
err := unix.Statfs(path, statfs)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ go_library(
|
|||
"//pkg/api/v1/helper:go_default_library",
|
||||
"//pkg/util/mount:go_default_library",
|
||||
"//vendor/github.com/golang/glog:go_default_library",
|
||||
"//vendor/golang.org/x/sys/unix:go_default_library",
|
||||
"//vendor/k8s.io/api/core/v1:go_default_library",
|
||||
"//vendor/k8s.io/api/storage/v1:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/api/resource:go_default_library",
|
||||
|
|
|
@ -23,7 +23,8 @@ import (
|
|||
"fmt"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
)
|
||||
|
@ -31,8 +32,8 @@ import (
|
|||
// FSInfo linux returns (available bytes, byte capacity, byte usage, total inodes, inodes free, inode usage, error)
|
||||
// for the filesystem that path resides upon.
|
||||
func FsInfo(path string) (int64, int64, int64, int64, int64, int64, error) {
|
||||
statfs := &syscall.Statfs_t{}
|
||||
err := syscall.Statfs(path, statfs)
|
||||
statfs := &unix.Statfs_t{}
|
||||
err := unix.Statfs(path, statfs)
|
||||
if err != nil {
|
||||
return 0, 0, 0, 0, 0, 0, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue