Merge pull request #231 from mlaventure/fix-ctr-file-leak-and-exec-after-restore

Fix ctr file leak and exec after restore
This commit is contained in:
Michael Crosby 2016-05-06 10:45:31 -07:00
commit 269487be8f
3 changed files with 14 additions and 2 deletions

View file

@ -164,6 +164,11 @@ var startCommand = cli.Command{
fatal(fmt.Sprintf("cannot get the absolute path of the bundle: %v", err), 1) fatal(fmt.Sprintf("cannot get the absolute path of the bundle: %v", err), 1)
} }
s, err := createStdio() s, err := createStdio()
defer func() {
if s.stdin != "" {
os.RemoveAll(filepath.Dir(s.stdin))
}
}()
if err != nil { if err != nil {
fatal(err.Error(), 1) fatal(err.Error(), 1)
} }
@ -463,6 +468,11 @@ var execCommand = cli.Command{
}, },
} }
s, err := createStdio() s, err := createStdio()
defer func() {
if s.stdin != "" {
os.RemoveAll(filepath.Dir(s.stdin))
}
}()
if err != nil { if err != nil {
fatal(err.Error(), 1) fatal(err.Error(), 1)
} }

View file

@ -130,6 +130,7 @@ func New(opts ContainerOpts) (Container, error) {
Labels: c.labels, Labels: c.labels,
Runtime: c.runtime, Runtime: c.runtime,
RuntimeArgs: c.runtimeArgs, RuntimeArgs: c.runtimeArgs,
Shim: c.shim,
NoPivotRoot: opts.NoPivotRoot, NoPivotRoot: opts.NoPivotRoot,
}); err != nil { }); err != nil {
return nil, err return nil, err
@ -137,7 +138,7 @@ func New(opts ContainerOpts) (Container, error) {
return c, nil return c, nil
} }
func Load(root, id string) (Container, error) { func Load(root, id string, timeout time.Duration) (Container, error) {
var s state var s state
f, err := os.Open(filepath.Join(root, id, StateFile)) f, err := os.Open(filepath.Join(root, id, StateFile))
if err != nil { if err != nil {
@ -157,6 +158,7 @@ func Load(root, id string) (Container, error) {
shim: s.Shim, shim: s.Shim,
noPivotRoot: s.NoPivotRoot, noPivotRoot: s.NoPivotRoot,
processes: make(map[string]*process), processes: make(map[string]*process),
timeout: timeout,
} }
dirs, err := ioutil.ReadDir(filepath.Join(root, id)) dirs, err := ioutil.ReadDir(filepath.Join(root, id))
if err != nil { if err != nil {

View file

@ -305,7 +305,7 @@ func (s *Supervisor) restore() error {
continue continue
} }
id := d.Name() id := d.Name()
container, err := runtime.Load(s.stateDir, id) container, err := runtime.Load(s.stateDir, id, s.timeout)
if err != nil { if err != nil {
return err return err
} }