summaryrefslogtreecommitdiffhomepage
path: root/pkg
diff options
context:
space:
mode:
authorNicolas Lacasse <nlacasse@google.com>2018-06-22 14:09:34 -0700
committerShentubot <shentubot@google.com>2018-06-22 14:10:30 -0700
commite0e640981282ece051c33700f4e272047fa4e5b6 (patch)
tree2f02a057f8adf07ee123c3467306e926c69d0307 /pkg
parentfe3fc44da3ca47fa27d55294e6c31d51b6b5dc14 (diff)
Simplify some handle logic.
PiperOrigin-RevId: 201738936 Change-Id: Ib75136415e28e8df0c742acd6b9512d4809fe3a8
Diffstat (limited to 'pkg')
-rw-r--r--pkg/sentry/fs/gofer/handles.go45
1 files changed, 15 insertions, 30 deletions
diff --git a/pkg/sentry/fs/gofer/handles.go b/pkg/sentry/fs/gofer/handles.go
index a660c9230..a3e52aad6 100644
--- a/pkg/sentry/fs/gofer/handles.go
+++ b/pkg/sentry/fs/gofer/handles.go
@@ -62,43 +62,28 @@ func newHandles(ctx context.Context, file contextFile, flags fs.FileFlags) (*han
return nil, err
}
+ var p9flags p9.OpenFlags
switch {
case flags.Read && flags.Write:
- hostFile, _, _, err := newFile.open(ctx, p9.ReadWrite)
- if err != nil {
- newFile.close(ctx)
- return nil, err
- }
- h := &handles{
- File: newFile,
- Host: hostFile,
- }
- return h, nil
+ p9flags = p9.ReadWrite
case flags.Read && !flags.Write:
- hostFile, _, _, err := newFile.open(ctx, p9.ReadOnly)
- if err != nil {
- newFile.close(ctx)
- return nil, err
- }
- h := &handles{
- File: newFile,
- Host: hostFile,
- }
- return h, nil
+ p9flags = p9.ReadOnly
case !flags.Read && flags.Write:
- hostFile, _, _, err := newFile.open(ctx, p9.WriteOnly)
- if err != nil {
- newFile.close(ctx)
- return nil, err
- }
- h := &handles{
- File: newFile,
- Host: hostFile,
- }
- return h, nil
+ p9flags = p9.WriteOnly
default:
panic("impossible fs.FileFlags")
}
+
+ hostFile, _, _, err := newFile.open(ctx, p9flags)
+ if err != nil {
+ newFile.close(ctx)
+ return nil, err
+ }
+ h := &handles{
+ File: newFile,
+ Host: hostFile,
+ }
+ return h, nil
}
type handleReadWriter struct {