diff options
author | Fabricio Voznika <fvoznika@google.com> | 2019-05-15 14:35:30 -0700 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2019-05-15 14:36:28 -0700 |
commit | ecb0f00e10017e82698c326b4d83294c9e20dfbd (patch) | |
tree | 999d825e80a29625a9efb60fe45a0959cac0b4a9 /runsc/boot/controller.go | |
parent | 85380ff03d21da417ad74d28b293c768d7effb4f (diff) |
Cleanup around urpc file payload handling
urpc always closes all files once the RPC function returns.
PiperOrigin-RevId: 248406857
Change-Id: I400a8562452ec75c8e4bddc2154948567d572950
Diffstat (limited to 'runsc/boot/controller.go')
-rw-r--r-- | runsc/boot/controller.go | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/runsc/boot/controller.go b/runsc/boot/controller.go index 86f06bff1..f09c1bd85 100644 --- a/runsc/boot/controller.go +++ b/runsc/boot/controller.go @@ -211,12 +211,6 @@ type StartArgs struct { func (cm *containerManager) Start(args *StartArgs, _ *struct{}) error { log.Debugf("containerManager.Start: %+v", args) - defer func() { - for _, f := range args.FilePayload.Files { - f.Close() - } - }() - // Validate arguments. if args == nil { return errors.New("start missing arguments") @@ -305,21 +299,19 @@ type RestoreOpts struct { func (cm *containerManager) Restore(o *RestoreOpts, _ *struct{}) error { log.Debugf("containerManager.Restore") - var specFile *os.File - deviceFD := -1 + var specFile, deviceFile *os.File switch numFiles := len(o.FilePayload.Files); numFiles { case 2: - var err error // The device file is donated to the platform. // Can't take ownership away from os.File. dup them to get a new FD. - deviceFD, err = syscall.Dup(int(o.FilePayload.Files[1].Fd())) + fd, err := syscall.Dup(int(o.FilePayload.Files[1].Fd())) if err != nil { return fmt.Errorf("failed to dup file: %v", err) } + deviceFile = os.NewFile(uintptr(fd), "platform device") fallthrough case 1: specFile = o.FilePayload.Files[0] - defer specFile.Close() case 0: return fmt.Errorf("at least one file must be passed to Restore") default: @@ -331,7 +323,7 @@ func (cm *containerManager) Restore(o *RestoreOpts, _ *struct{}) error { cm.l.k.Pause() cm.l.k.Destroy() - p, err := createPlatform(cm.l.conf, deviceFD) + p, err := createPlatform(cm.l.conf, deviceFile) if err != nil { return fmt.Errorf("creating platform: %v", err) } @@ -357,7 +349,7 @@ func (cm *containerManager) Restore(o *RestoreOpts, _ *struct{}) error { if eps, ok := networkStack.(*epsocket.Stack); ok { stack.StackFromEnv = eps.Stack // FIXME(b/36201077) } - info, err := o.FilePayload.Files[0].Stat() + info, err := specFile.Stat() if err != nil { return err } @@ -366,9 +358,7 @@ func (cm *containerManager) Restore(o *RestoreOpts, _ *struct{}) error { } // Load the state. - loadOpts := state.LoadOpts{ - Source: o.FilePayload.Files[0], - } + loadOpts := state.LoadOpts{Source: specFile} if err := loadOpts.Load(k, networkStack); err != nil { return err } |