Skip to content

Commit ef344c1

Browse files
authored
Merge pull request containerd#1312 from tklauser/use-x-sys
Use functions from golang.org/x/sys
2 parents 29a4dd7 + f2bed8f commit ef344c1

File tree

9 files changed

+39
-34
lines changed

9 files changed

+39
-34
lines changed

archive/tar_unix.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/dmcgowan/go-tar"
1212
"github.com/opencontainers/runc/libcontainer/system"
1313
"github.com/pkg/errors"
14+
"golang.org/x/sys/unix"
1415
)
1516

1617
func tarName(p string) (string, error) {
@@ -64,9 +65,9 @@ func mkdirAll(path string, perm os.FileMode) error {
6465
func prepareApply() func() {
6566
// Unset unmask before doing an apply operation,
6667
// restore unmask when complete
67-
oldmask := syscall.Umask(0)
68+
oldmask := unix.Umask(0)
6869
return func() {
69-
syscall.Umask(oldmask)
70+
unix.Umask(oldmask)
7071
}
7172
}
7273

@@ -95,14 +96,14 @@ func handleTarTypeBlockCharFifo(hdr *tar.Header, path string) error {
9596
mode := uint32(hdr.Mode & 07777)
9697
switch hdr.Typeflag {
9798
case tar.TypeBlock:
98-
mode |= syscall.S_IFBLK
99+
mode |= unix.S_IFBLK
99100
case tar.TypeChar:
100-
mode |= syscall.S_IFCHR
101+
mode |= unix.S_IFCHR
101102
case tar.TypeFifo:
102-
mode |= syscall.S_IFIFO
103+
mode |= unix.S_IFIFO
103104
}
104105

105-
return syscall.Mknod(path, mode, int(mkdev(hdr.Devmajor, hdr.Devminor)))
106+
return unix.Mknod(path, mode, int(mkdev(hdr.Devmajor, hdr.Devminor)))
106107
}
107108

108109
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 {
122123

123124
func getxattr(path, attr string) ([]byte, error) {
124125
b, err := sysx.LGetxattr(path, attr)
125-
if err == syscall.ENOTSUP || err == sysx.ENODATA {
126+
if err == unix.ENOTSUP || err == unix.ENODATA {
126127
return nil, nil
127128
}
128129
return b, err

archive/time_windows.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
package archive
22

33
import (
4-
"syscall"
54
"time"
5+
6+
"golang.org/x/sys/windows"
67
)
78

89
// chtimes will set the create time on a file using the given modtime.
910
// This requires calling SetFileTime and explicitly including the create time.
1011
func chtimes(path string, atime, mtime time.Time) error {
11-
ctimespec := syscall.NsecToTimespec(mtime.UnixNano())
12-
pathp, e := syscall.UTF16PtrFromString(path)
12+
ctimespec := windows.NsecToTimespec(mtime.UnixNano())
13+
pathp, e := windows.UTF16PtrFromString(path)
1314
if e != nil {
1415
return e
1516
}
16-
h, e := syscall.CreateFile(pathp,
17-
syscall.FILE_WRITE_ATTRIBUTES, syscall.FILE_SHARE_WRITE, nil,
18-
syscall.OPEN_EXISTING, syscall.FILE_FLAG_BACKUP_SEMANTICS, 0)
17+
h, e := windows.CreateFile(pathp,
18+
windows.FILE_WRITE_ATTRIBUTES, windows.FILE_SHARE_WRITE, nil,
19+
windows.OPEN_EXISTING, windows.FILE_FLAG_BACKUP_SEMANTICS, 0)
1920
if e != nil {
2021
return e
2122
}
22-
defer syscall.Close(h)
23-
c := syscall.NsecToFiletime(syscall.TimespecToNsec(ctimespec))
24-
return syscall.SetFileTime(h, &c, nil, nil)
23+
defer windows.Close(h)
24+
c := windows.NsecToFiletime(windows.TimespecToNsec(ctimespec))
25+
return windows.SetFileTime(h, &c, nil, nil)
2526
}

cmd/containerd-shim/shim_linux.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import (
44
"net"
55
"os"
66
"os/signal"
7-
"syscall"
87

98
"google.golang.org/grpc"
109
"google.golang.org/grpc/credentials"
1110

1211
"golang.org/x/net/context"
12+
"golang.org/x/sys/unix"
1313

1414
"github.com/containerd/containerd/reaper"
1515
"github.com/containerd/containerd/sys"
@@ -60,7 +60,7 @@ func (u *unixSocketCredentials) ServerHandshake(c net.Conn) (net.Conn, credentia
6060
if err != nil {
6161
return nil, nil, errors.Wrap(err, "unixSocketCredentials: failed to retrieve connection underlying fd")
6262
}
63-
pcred, err := syscall.GetsockoptUcred(int(f.Fd()), syscall.SOL_SOCKET, syscall.SO_PEERCRED)
63+
pcred, err := unix.GetsockoptUcred(int(f.Fd()), unix.SOL_SOCKET, unix.SO_PEERCRED)
6464
if err != nil {
6565
return nil, nil, errors.Wrap(err, "unixSocketCredentials: failed to retrieve socket peer credentials")
6666
}

cmd/containerd/main_windows.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ import (
44
"context"
55
"os"
66
"path/filepath"
7-
"syscall"
87

98
"github.com/containerd/containerd/log"
109
"github.com/containerd/containerd/server"
10+
11+
"golang.org/x/sys/windows"
1112
)
1213

1314
var (
1415
defaultConfigPath = filepath.Join(os.Getenv("programfiles"), "containerd", "config.toml")
1516
handledSignals = []os.Signal{
16-
syscall.SIGTERM,
17-
syscall.SIGINT,
17+
windows.SIGTERM,
18+
windows.SIGINT,
1819
}
1920
)
2021

cmd/ctr/utils_unix.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@ import (
99
"net"
1010
"os"
1111
"sync"
12-
"syscall"
1312
"time"
1413

1514
"github.com/containerd/fifo"
1615
"github.com/pkg/errors"
1716
"github.com/urfave/cli"
17+
"golang.org/x/sys/unix"
1818
"google.golang.org/grpc"
1919
)
2020

2121
func prepareStdio(stdin, stdout, stderr string, console bool) (wg *sync.WaitGroup, err error) {
2222
wg = &sync.WaitGroup{}
2323
ctx := gocontext.Background()
2424

25-
f, err := fifo.OpenFifo(ctx, stdin, syscall.O_WRONLY|syscall.O_CREAT|syscall.O_NONBLOCK, 0700)
25+
f, err := fifo.OpenFifo(ctx, stdin, unix.O_WRONLY|unix.O_CREAT|unix.O_NONBLOCK, 0700)
2626
if err != nil {
2727
return nil, err
2828
}
@@ -36,7 +36,7 @@ func prepareStdio(stdin, stdout, stderr string, console bool) (wg *sync.WaitGrou
3636
w.Close()
3737
}(f)
3838

39-
f, err = fifo.OpenFifo(ctx, stdout, syscall.O_RDONLY|syscall.O_CREAT|syscall.O_NONBLOCK, 0700)
39+
f, err = fifo.OpenFifo(ctx, stdout, unix.O_RDONLY|unix.O_CREAT|unix.O_NONBLOCK, 0700)
4040
if err != nil {
4141
return nil, err
4242
}
@@ -52,7 +52,7 @@ func prepareStdio(stdin, stdout, stderr string, console bool) (wg *sync.WaitGrou
5252
wg.Done()
5353
}(f)
5454

55-
f, err = fifo.OpenFifo(ctx, stderr, syscall.O_RDONLY|syscall.O_CREAT|syscall.O_NONBLOCK, 0700)
55+
f, err = fifo.OpenFifo(ctx, stderr, unix.O_RDONLY|unix.O_CREAT|unix.O_NONBLOCK, 0700)
5656
if err != nil {
5757
return nil, err
5858
}

container_linux_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ package containerd
44

55
import (
66
"context"
7-
"syscall"
87
"testing"
98

109
"github.com/containerd/cgroups"
1110
"github.com/containerd/containerd/linux/runcopts"
1211
specs "github.com/opencontainers/runtime-spec/specs-go"
12+
"golang.org/x/sys/unix"
1313
)
1414

1515
func TestContainerUpdate(t *testing.T) {
@@ -93,7 +93,7 @@ func TestContainerUpdate(t *testing.T) {
9393
if int64(stat.Memory.Usage.Limit) != limit {
9494
t.Errorf("expected memory limit to be set to %d but received %d", limit, stat.Memory.Usage.Limit)
9595
}
96-
if err := task.Kill(ctx, syscall.SIGKILL); err != nil {
96+
if err := task.Kill(ctx, unix.SIGKILL); err != nil {
9797
t.Error(err)
9898
return
9999
}
@@ -168,7 +168,7 @@ func TestShimInCgroup(t *testing.T) {
168168
if len(processes) == 0 {
169169
t.Errorf("created cgroup should have atleast one process inside: %d", len(processes))
170170
}
171-
if err := task.Kill(ctx, syscall.SIGKILL); err != nil {
171+
if err := task.Kill(ctx, unix.SIGKILL); err != nil {
172172
t.Error(err)
173173
return
174174
}

fs/copy_linux.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ func copyFileContent(dst, src *os.File) error {
3737
return errors.Wrap(err, "unable to stat source")
3838
}
3939

40-
n, err := sysx.CopyFileRange(src.Fd(), nil, dst.Fd(), nil, int(st.Size()), 0)
40+
n, err := unix.CopyFileRange(int(src.Fd()), nil, int(dst.Fd()), nil, int(st.Size()), 0)
4141
if err != nil {
42-
if err != syscall.ENOSYS && err != syscall.EXDEV {
42+
if err != unix.ENOSYS && err != unix.EXDEV {
4343
return errors.Wrap(err, "copy file range failed")
4444
}
4545

@@ -79,5 +79,5 @@ func copyDevice(dst string, fi os.FileInfo) error {
7979
if !ok {
8080
return errors.New("unsupported stat type")
8181
}
82-
return syscall.Mknod(dst, uint32(fi.Mode()), int(st.Rdev))
82+
return unix.Mknod(dst, uint32(fi.Mode()), int(st.Rdev))
8383
}

fs/copy_unix.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/containerd/containerd/sys"
1111
"github.com/containerd/continuity/sysx"
1212
"github.com/pkg/errors"
13+
"golang.org/x/sys/unix"
1314
)
1415

1516
func copyFileInfo(fi os.FileInfo, name string) error {
@@ -63,5 +64,5 @@ func copyDevice(dst string, fi os.FileInfo) error {
6364
if !ok {
6465
return errors.New("unsupported stat type")
6566
}
66-
return syscall.Mknod(dst, uint32(fi.Mode()), int(st.Rdev))
67+
return unix.Mknod(dst, uint32(fi.Mode()), int(st.Rdev))
6768
}

fs/diff_unix.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/containerd/continuity/sysx"
1313
"github.com/pkg/errors"
14+
"golang.org/x/sys/unix"
1415
)
1516

1617
// whiteouts are files with a special meaning for the layered filesystem.
@@ -83,11 +84,11 @@ func compareSysStat(s1, s2 interface{}) (bool, error) {
8384

8485
func compareCapabilities(p1, p2 string) (bool, error) {
8586
c1, err := sysx.LGetxattr(p1, "security.capability")
86-
if err != nil && err != sysx.ENODATA {
87+
if err != nil && err != unix.ENODATA {
8788
return false, errors.Wrapf(err, "failed to get xattr for %s", p1)
8889
}
8990
c2, err := sysx.LGetxattr(p2, "security.capability")
90-
if err != nil && err != sysx.ENODATA {
91+
if err != nil && err != unix.ENODATA {
9192
return false, errors.Wrapf(err, "failed to get xattr for %s", p2)
9293
}
9394
return bytes.Equal(c1, c2), nil

0 commit comments

Comments
 (0)