Merge pull request #552 from hqhq/defer_f_close

Close shim file when cmd.Start fail
This commit is contained in:
Michael Crosby 2017-02-21 11:25:28 -08:00 committed by GitHub
commit 23d3818060

View file

@ -30,6 +30,9 @@ func newShim(path string) (shim.ShimClient, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
// close our side of the socket, do not close the listener as it will
// remove the socket from disk
defer f.Close()
cmd.ExtraFiles = append(cmd.ExtraFiles, f) cmd.ExtraFiles = append(cmd.ExtraFiles, f)
// make sure the shim can be re-parented to system init // make sure the shim can be re-parented to system init
// and is cloned in a new mount namespace because the overlay/filesystems // and is cloned in a new mount namespace because the overlay/filesystems
@ -41,9 +44,6 @@ func newShim(path string) (shim.ShimClient, error) {
if err := cmd.Start(); err != nil { if err := cmd.Start(); err != nil {
return nil, errors.Wrapf(err, "failed to start shim") return nil, errors.Wrapf(err, "failed to start shim")
} }
// close our side of the socket, do not close the listener as it will
// remove the socket from disk
f.Close()
// since we are currently the parent go ahead and make sure we wait on the shim // since we are currently the parent go ahead and make sure we wait on the shim
go cmd.Wait() go cmd.Wait()
return connectShim(socket) return connectShim(socket)