Merge pull request #1312 from tklauser/use-x-sys
Use functions from golang.org/x/sys
This commit is contained in:
commit
ef344c14ba
@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/dmcgowan/go-tar"
|
"github.com/dmcgowan/go-tar"
|
||||||
"github.com/opencontainers/runc/libcontainer/system"
|
"github.com/opencontainers/runc/libcontainer/system"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
func tarName(p string) (string, error) {
|
func tarName(p string) (string, error) {
|
||||||
@ -64,9 +65,9 @@ func mkdirAll(path string, perm os.FileMode) error {
|
|||||||
func prepareApply() func() {
|
func prepareApply() func() {
|
||||||
// Unset unmask before doing an apply operation,
|
// Unset unmask before doing an apply operation,
|
||||||
// restore unmask when complete
|
// restore unmask when complete
|
||||||
oldmask := syscall.Umask(0)
|
oldmask := unix.Umask(0)
|
||||||
return func() {
|
return func() {
|
||||||
syscall.Umask(oldmask)
|
unix.Umask(oldmask)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,14 +96,14 @@ func handleTarTypeBlockCharFifo(hdr *tar.Header, path string) error {
|
|||||||
mode := uint32(hdr.Mode & 07777)
|
mode := uint32(hdr.Mode & 07777)
|
||||||
switch hdr.Typeflag {
|
switch hdr.Typeflag {
|
||||||
case tar.TypeBlock:
|
case tar.TypeBlock:
|
||||||
mode |= syscall.S_IFBLK
|
mode |= unix.S_IFBLK
|
||||||
case tar.TypeChar:
|
case tar.TypeChar:
|
||||||
mode |= syscall.S_IFCHR
|
mode |= unix.S_IFCHR
|
||||||
case tar.TypeFifo:
|
case tar.TypeFifo:
|
||||||
mode |= syscall.S_IFIFO
|
mode |= unix.S_IFIFO
|
||||||
}
|
}
|
||||||
|
|
||||||
return syscall.Mknod(path, mode, int(mkdev(hdr.Devmajor, hdr.Devminor)))
|
return unix.Mknod(path, mode, int(mkdev(hdr.Devmajor, hdr.Devminor)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleLChmod(hdr *tar.Header, path string, hdrInfo os.FileInfo) error {
|
func handleLChmod(hdr *tar.Header, path string, hdrInfo os.FileInfo) error {
|
||||||
@ -122,7 +123,7 @@ func handleLChmod(hdr *tar.Header, path string, hdrInfo os.FileInfo) error {
|
|||||||
|
|
||||||
func getxattr(path, attr string) ([]byte, error) {
|
func getxattr(path, attr string) ([]byte, error) {
|
||||||
b, err := sysx.LGetxattr(path, attr)
|
b, err := sysx.LGetxattr(path, attr)
|
||||||
if err == syscall.ENOTSUP || err == sysx.ENODATA {
|
if err == unix.ENOTSUP || err == unix.ENODATA {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
return b, err
|
return b, err
|
||||||
|
@ -1,25 +1,26 @@
|
|||||||
package archive
|
package archive
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"syscall"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/sys/windows"
|
||||||
)
|
)
|
||||||
|
|
||||||
// chtimes will set the create time on a file using the given modtime.
|
// chtimes will set the create time on a file using the given modtime.
|
||||||
// This requires calling SetFileTime and explicitly including the create time.
|
// This requires calling SetFileTime and explicitly including the create time.
|
||||||
func chtimes(path string, atime, mtime time.Time) error {
|
func chtimes(path string, atime, mtime time.Time) error {
|
||||||
ctimespec := syscall.NsecToTimespec(mtime.UnixNano())
|
ctimespec := windows.NsecToTimespec(mtime.UnixNano())
|
||||||
pathp, e := syscall.UTF16PtrFromString(path)
|
pathp, e := windows.UTF16PtrFromString(path)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
h, e := syscall.CreateFile(pathp,
|
h, e := windows.CreateFile(pathp,
|
||||||
syscall.FILE_WRITE_ATTRIBUTES, syscall.FILE_SHARE_WRITE, nil,
|
windows.FILE_WRITE_ATTRIBUTES, windows.FILE_SHARE_WRITE, nil,
|
||||||
syscall.OPEN_EXISTING, syscall.FILE_FLAG_BACKUP_SEMANTICS, 0)
|
windows.OPEN_EXISTING, windows.FILE_FLAG_BACKUP_SEMANTICS, 0)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
defer syscall.Close(h)
|
defer windows.Close(h)
|
||||||
c := syscall.NsecToFiletime(syscall.TimespecToNsec(ctimespec))
|
c := windows.NsecToFiletime(windows.TimespecToNsec(ctimespec))
|
||||||
return syscall.SetFileTime(h, &c, nil, nil)
|
return windows.SetFileTime(h, &c, nil, nil)
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,12 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
|
||||||
|
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/credentials"
|
"google.golang.org/grpc/credentials"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
|
|
||||||
"github.com/containerd/containerd/reaper"
|
"github.com/containerd/containerd/reaper"
|
||||||
"github.com/containerd/containerd/sys"
|
"github.com/containerd/containerd/sys"
|
||||||
@ -60,7 +60,7 @@ func (u *unixSocketCredentials) ServerHandshake(c net.Conn) (net.Conn, credentia
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, errors.Wrap(err, "unixSocketCredentials: failed to retrieve connection underlying fd")
|
return nil, nil, errors.Wrap(err, "unixSocketCredentials: failed to retrieve connection underlying fd")
|
||||||
}
|
}
|
||||||
pcred, err := syscall.GetsockoptUcred(int(f.Fd()), syscall.SOL_SOCKET, syscall.SO_PEERCRED)
|
pcred, err := unix.GetsockoptUcred(int(f.Fd()), unix.SOL_SOCKET, unix.SO_PEERCRED)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, errors.Wrap(err, "unixSocketCredentials: failed to retrieve socket peer credentials")
|
return nil, nil, errors.Wrap(err, "unixSocketCredentials: failed to retrieve socket peer credentials")
|
||||||
}
|
}
|
||||||
|
@ -4,17 +4,18 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"syscall"
|
|
||||||
|
|
||||||
"github.com/containerd/containerd/log"
|
"github.com/containerd/containerd/log"
|
||||||
"github.com/containerd/containerd/server"
|
"github.com/containerd/containerd/server"
|
||||||
|
|
||||||
|
"golang.org/x/sys/windows"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
defaultConfigPath = filepath.Join(os.Getenv("programfiles"), "containerd", "config.toml")
|
defaultConfigPath = filepath.Join(os.Getenv("programfiles"), "containerd", "config.toml")
|
||||||
handledSignals = []os.Signal{
|
handledSignals = []os.Signal{
|
||||||
syscall.SIGTERM,
|
windows.SIGTERM,
|
||||||
syscall.SIGINT,
|
windows.SIGINT,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -9,12 +9,12 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containerd/fifo"
|
"github.com/containerd/fifo"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ func prepareStdio(stdin, stdout, stderr string, console bool) (wg *sync.WaitGrou
|
|||||||
wg = &sync.WaitGroup{}
|
wg = &sync.WaitGroup{}
|
||||||
ctx := gocontext.Background()
|
ctx := gocontext.Background()
|
||||||
|
|
||||||
f, err := fifo.OpenFifo(ctx, stdin, syscall.O_WRONLY|syscall.O_CREAT|syscall.O_NONBLOCK, 0700)
|
f, err := fifo.OpenFifo(ctx, stdin, unix.O_WRONLY|unix.O_CREAT|unix.O_NONBLOCK, 0700)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -36,7 +36,7 @@ func prepareStdio(stdin, stdout, stderr string, console bool) (wg *sync.WaitGrou
|
|||||||
w.Close()
|
w.Close()
|
||||||
}(f)
|
}(f)
|
||||||
|
|
||||||
f, err = fifo.OpenFifo(ctx, stdout, syscall.O_RDONLY|syscall.O_CREAT|syscall.O_NONBLOCK, 0700)
|
f, err = fifo.OpenFifo(ctx, stdout, unix.O_RDONLY|unix.O_CREAT|unix.O_NONBLOCK, 0700)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -52,7 +52,7 @@ func prepareStdio(stdin, stdout, stderr string, console bool) (wg *sync.WaitGrou
|
|||||||
wg.Done()
|
wg.Done()
|
||||||
}(f)
|
}(f)
|
||||||
|
|
||||||
f, err = fifo.OpenFifo(ctx, stderr, syscall.O_RDONLY|syscall.O_CREAT|syscall.O_NONBLOCK, 0700)
|
f, err = fifo.OpenFifo(ctx, stderr, unix.O_RDONLY|unix.O_CREAT|unix.O_NONBLOCK, 0700)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,12 @@ package containerd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"syscall"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/containerd/cgroups"
|
"github.com/containerd/cgroups"
|
||||||
"github.com/containerd/containerd/linux/runcopts"
|
"github.com/containerd/containerd/linux/runcopts"
|
||||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestContainerUpdate(t *testing.T) {
|
func TestContainerUpdate(t *testing.T) {
|
||||||
@ -93,7 +93,7 @@ func TestContainerUpdate(t *testing.T) {
|
|||||||
if int64(stat.Memory.Usage.Limit) != limit {
|
if int64(stat.Memory.Usage.Limit) != limit {
|
||||||
t.Errorf("expected memory limit to be set to %d but received %d", limit, stat.Memory.Usage.Limit)
|
t.Errorf("expected memory limit to be set to %d but received %d", limit, stat.Memory.Usage.Limit)
|
||||||
}
|
}
|
||||||
if err := task.Kill(ctx, syscall.SIGKILL); err != nil {
|
if err := task.Kill(ctx, unix.SIGKILL); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -168,7 +168,7 @@ func TestShimInCgroup(t *testing.T) {
|
|||||||
if len(processes) == 0 {
|
if len(processes) == 0 {
|
||||||
t.Errorf("created cgroup should have atleast one process inside: %d", len(processes))
|
t.Errorf("created cgroup should have atleast one process inside: %d", len(processes))
|
||||||
}
|
}
|
||||||
if err := task.Kill(ctx, syscall.SIGKILL); err != nil {
|
if err := task.Kill(ctx, unix.SIGKILL); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -37,9 +37,9 @@ func copyFileContent(dst, src *os.File) error {
|
|||||||
return errors.Wrap(err, "unable to stat source")
|
return errors.Wrap(err, "unable to stat source")
|
||||||
}
|
}
|
||||||
|
|
||||||
n, err := sysx.CopyFileRange(src.Fd(), nil, dst.Fd(), nil, int(st.Size()), 0)
|
n, err := unix.CopyFileRange(int(src.Fd()), nil, int(dst.Fd()), nil, int(st.Size()), 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err != syscall.ENOSYS && err != syscall.EXDEV {
|
if err != unix.ENOSYS && err != unix.EXDEV {
|
||||||
return errors.Wrap(err, "copy file range failed")
|
return errors.Wrap(err, "copy file range failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,5 +79,5 @@ func copyDevice(dst string, fi os.FileInfo) error {
|
|||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("unsupported stat type")
|
return errors.New("unsupported stat type")
|
||||||
}
|
}
|
||||||
return syscall.Mknod(dst, uint32(fi.Mode()), int(st.Rdev))
|
return unix.Mknod(dst, uint32(fi.Mode()), int(st.Rdev))
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/containerd/containerd/sys"
|
"github.com/containerd/containerd/sys"
|
||||||
"github.com/containerd/continuity/sysx"
|
"github.com/containerd/continuity/sysx"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
func copyFileInfo(fi os.FileInfo, name string) error {
|
func copyFileInfo(fi os.FileInfo, name string) error {
|
||||||
@ -63,5 +64,5 @@ func copyDevice(dst string, fi os.FileInfo) error {
|
|||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("unsupported stat type")
|
return errors.New("unsupported stat type")
|
||||||
}
|
}
|
||||||
return syscall.Mknod(dst, uint32(fi.Mode()), int(st.Rdev))
|
return unix.Mknod(dst, uint32(fi.Mode()), int(st.Rdev))
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
|
|
||||||
"github.com/containerd/continuity/sysx"
|
"github.com/containerd/continuity/sysx"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
// whiteouts are files with a special meaning for the layered filesystem.
|
// whiteouts are files with a special meaning for the layered filesystem.
|
||||||
@ -83,11 +84,11 @@ func compareSysStat(s1, s2 interface{}) (bool, error) {
|
|||||||
|
|
||||||
func compareCapabilities(p1, p2 string) (bool, error) {
|
func compareCapabilities(p1, p2 string) (bool, error) {
|
||||||
c1, err := sysx.LGetxattr(p1, "security.capability")
|
c1, err := sysx.LGetxattr(p1, "security.capability")
|
||||||
if err != nil && err != sysx.ENODATA {
|
if err != nil && err != unix.ENODATA {
|
||||||
return false, errors.Wrapf(err, "failed to get xattr for %s", p1)
|
return false, errors.Wrapf(err, "failed to get xattr for %s", p1)
|
||||||
}
|
}
|
||||||
c2, err := sysx.LGetxattr(p2, "security.capability")
|
c2, err := sysx.LGetxattr(p2, "security.capability")
|
||||||
if err != nil && err != sysx.ENODATA {
|
if err != nil && err != unix.ENODATA {
|
||||||
return false, errors.Wrapf(err, "failed to get xattr for %s", p2)
|
return false, errors.Wrapf(err, "failed to get xattr for %s", p2)
|
||||||
}
|
}
|
||||||
return bytes.Equal(c1, c2), nil
|
return bytes.Equal(c1, c2), nil
|
||||||
|
Loading…
Reference in New Issue
Block a user