Skip to content

Commit ae22f10

Browse files
committed
Cleanup ctr stdio tmp directory
Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
1 parent 03e5862 commit ae22f10

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

ctr/container.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,10 @@ var startCommand = cli.Command{
182182
if err != nil {
183183
fatal(fmt.Sprintf("cannot get the absolute path of the bundle: %v", err), 1)
184184
}
185-
s, err := createStdio()
185+
s, tmpDir, err := createStdio()
186186
defer func() {
187-
if s.stdin != "" {
188-
os.RemoveAll(filepath.Dir(s.stdin))
187+
if tmpDir != "" {
188+
os.RemoveAll(tmpDir)
189189
}
190190
}()
191191
if err != nil {
@@ -489,10 +489,10 @@ var execCommand = cli.Command{
489489
Gid: uint32(context.Int("gid")),
490490
},
491491
}
492-
s, err := createStdio()
492+
s, tmpDir, err := createStdio()
493493
defer func() {
494-
if s.stdin != "" {
495-
os.RemoveAll(filepath.Dir(s.stdin))
494+
if tmpDir != "" {
495+
os.RemoveAll(tmpDir)
496496
}
497497
}()
498498
if err != nil {
@@ -684,10 +684,10 @@ type stdio struct {
684684
stderr string
685685
}
686686

687-
func createStdio() (s stdio, err error) {
688-
tmp, err := ioutil.TempDir("", "ctr-")
687+
func createStdio() (s stdio, tmp string, err error) {
688+
tmp, err = ioutil.TempDir("", "ctr-")
689689
if err != nil {
690-
return s, err
690+
return s, tmp, err
691691
}
692692
// create fifo's for the process
693693
for name, fd := range map[string]*string{
@@ -697,9 +697,9 @@ func createStdio() (s stdio, err error) {
697697
} {
698698
path := filepath.Join(tmp, name)
699699
if err := unix.Mkfifo(path, 0755); err != nil && !os.IsExist(err) {
700-
return s, err
700+
return s, tmp, err
701701
}
702702
*fd = path
703703
}
704-
return s, nil
704+
return s, tmp, nil
705705
}

0 commit comments

Comments
 (0)