diff options
author | Ayush Ranjan <ayushranjan@google.com> | 2021-03-03 10:23:55 -0800 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-03-03 10:25:58 -0800 |
commit | a9441aea2780da8c93da1c73da860219f98438de (patch) | |
tree | 8b12915756f5bfb926218214cd7bc0b3281605fd /pkg/sentry/fsimpl/gofer | |
parent | b8a5420f49a2afd622ec08b5019e1bf537f7da82 (diff) |
[op] Replace syscall package usage with golang.org/x/sys/unix in pkg/.
The syscall package has been deprecated in favor of golang.org/x/sys.
Note that syscall is still used in the following places:
- pkg/sentry/socket/hostinet/stack.go: some netlink related functionalities
are not yet available in golang.org/x/sys.
- syscall.Stat_t is still used in some places because os.FileInfo.Sys() still
returns it and not unix.Stat_t.
Updates #214
PiperOrigin-RevId: 360701387
Diffstat (limited to 'pkg/sentry/fsimpl/gofer')
-rw-r--r-- | pkg/sentry/fsimpl/gofer/gofer.go | 18 | ||||
-rw-r--r-- | pkg/sentry/fsimpl/gofer/handle.go | 5 | ||||
-rw-r--r-- | pkg/sentry/fsimpl/gofer/socket.go | 5 | ||||
-rw-r--r-- | pkg/sentry/fsimpl/gofer/special_file.go | 4 |
4 files changed, 15 insertions, 17 deletions
diff --git a/pkg/sentry/fsimpl/gofer/gofer.go b/pkg/sentry/fsimpl/gofer/gofer.go index 094d993a8..1508cbdf1 100644 --- a/pkg/sentry/fsimpl/gofer/gofer.go +++ b/pkg/sentry/fsimpl/gofer/gofer.go @@ -40,8 +40,8 @@ import ( "strconv" "strings" "sync/atomic" - "syscall" + "golang.org/x/sys/unix" "gvisor.dev/gvisor/pkg/abi/linux" "gvisor.dev/gvisor/pkg/context" "gvisor.dev/gvisor/pkg/log" @@ -550,10 +550,10 @@ func (fs *filesystem) Release(ctx context.Context) { d.dataMu.Unlock() // Close host FDs if they exist. if d.readFD >= 0 { - syscall.Close(int(d.readFD)) + unix.Close(int(d.readFD)) } if d.writeFD >= 0 && d.readFD != d.writeFD { - syscall.Close(int(d.writeFD)) + unix.Close(int(d.writeFD)) } d.readFD = -1 d.writeFD = -1 @@ -1505,10 +1505,10 @@ func (d *dentry) destroyLocked(ctx context.Context) { d.readFile = p9file{} d.writeFile = p9file{} if d.readFD >= 0 { - syscall.Close(int(d.readFD)) + unix.Close(int(d.readFD)) } if d.writeFD >= 0 && d.readFD != d.writeFD { - syscall.Close(int(d.writeFD)) + unix.Close(int(d.writeFD)) } d.readFD = -1 d.writeFD = -1 @@ -1686,7 +1686,7 @@ func (d *dentry) ensureSharedHandle(ctx context.Context, read, write, trunc bool // may use the old or new file description, but this // doesn't matter since they refer to the same file, and // any racing mappings must be read-only. - if err := syscall.Dup3(int(h.fd), int(d.readFD), syscall.O_CLOEXEC); err != nil { + if err := unix.Dup3(int(h.fd), int(d.readFD), unix.O_CLOEXEC); err != nil { oldFD := d.readFD d.handleMu.Unlock() ctx.Warningf("gofer.dentry.ensureSharedHandle: failed to dup fd %d to fd %d: %v", h.fd, oldFD, err) @@ -1772,7 +1772,7 @@ func (d *dentry) ensureSharedHandle(ctx context.Context, read, write, trunc bool d.mapsMu.Unlock() } for _, fd := range fdsToClose { - syscall.Close(int(fd)) + unix.Close(int(fd)) } return nil @@ -1808,7 +1808,7 @@ func (d *dentry) syncRemoteFileLocked(ctx context.Context) error { // handles otherwise. if d.writeFD >= 0 { ctx.UninterruptibleSleepStart(false) - err := syscall.Fsync(int(d.writeFD)) + err := unix.Fsync(int(d.writeFD)) ctx.UninterruptibleSleepFinish(false) return err } @@ -1817,7 +1817,7 @@ func (d *dentry) syncRemoteFileLocked(ctx context.Context) error { } if d.readFD >= 0 { ctx.UninterruptibleSleepStart(false) - err := syscall.Fsync(int(d.readFD)) + err := unix.Fsync(int(d.readFD)) ctx.UninterruptibleSleepFinish(false) return err } diff --git a/pkg/sentry/fsimpl/gofer/handle.go b/pkg/sentry/fsimpl/gofer/handle.go index a9ebe1206..0bc201d1c 100644 --- a/pkg/sentry/fsimpl/gofer/handle.go +++ b/pkg/sentry/fsimpl/gofer/handle.go @@ -15,8 +15,7 @@ package gofer import ( - "syscall" - + "golang.org/x/sys/unix" "gvisor.dev/gvisor/pkg/context" "gvisor.dev/gvisor/pkg/p9" "gvisor.dev/gvisor/pkg/safemem" @@ -73,7 +72,7 @@ func (h *handle) close(ctx context.Context) { h.file.close(ctx) h.file = p9file{} if h.fd >= 0 { - syscall.Close(int(h.fd)) + unix.Close(int(h.fd)) h.fd = -1 } } diff --git a/pkg/sentry/fsimpl/gofer/socket.go b/pkg/sentry/fsimpl/gofer/socket.go index a21199eac..fe15f8583 100644 --- a/pkg/sentry/fsimpl/gofer/socket.go +++ b/pkg/sentry/fsimpl/gofer/socket.go @@ -15,8 +15,7 @@ package gofer import ( - "syscall" - + "golang.org/x/sys/unix" "gvisor.dev/gvisor/pkg/abi/linux" "gvisor.dev/gvisor/pkg/context" "gvisor.dev/gvisor/pkg/log" @@ -118,7 +117,7 @@ func (e *endpoint) newConnectedEndpoint(ctx context.Context, flags p9.ConnectFla return nil, syserr.ErrConnectionRefused } // Dup the fd so that the new endpoint can manage its lifetime. - hostFD, err := syscall.Dup(hostFile.FD()) + hostFD, err := unix.Dup(hostFile.FD()) if err != nil { log.Warningf("Could not dup host socket fd %d: %v", hostFile.FD(), err) return nil, syserr.FromError(err) diff --git a/pkg/sentry/fsimpl/gofer/special_file.go b/pkg/sentry/fsimpl/gofer/special_file.go index ae972fcb5..ac3b5b621 100644 --- a/pkg/sentry/fsimpl/gofer/special_file.go +++ b/pkg/sentry/fsimpl/gofer/special_file.go @@ -16,8 +16,8 @@ package gofer import ( "sync/atomic" - "syscall" + "golang.org/x/sys/unix" "gvisor.dev/gvisor/pkg/abi/linux" "gvisor.dev/gvisor/pkg/context" "gvisor.dev/gvisor/pkg/fdnotifier" @@ -376,7 +376,7 @@ func (fd *specialFileFD) sync(ctx context.Context, forFilesystemSync bool) error // RPC. if fd.handle.fd >= 0 { ctx.UninterruptibleSleepStart(false) - err := syscall.Fsync(int(fd.handle.fd)) + err := unix.Fsync(int(fd.handle.fd)) ctx.UninterruptibleSleepFinish(false) return err } |