Skip to content

Commit 78ab1d1

Browse files
committed
Correct logic of FIFO cleanup
Only delete files which are FIFOs and only delete directories which are empty after deleting FIFOs. Signed-off-by: Phil Estes <[email protected]>
1 parent 0c78dac commit 78ab1d1

1 file changed

Lines changed: 23 additions & 14 deletions

File tree

container.go

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"github.com/containerd/containerd/images"
3333
"github.com/containerd/containerd/oci"
3434
"github.com/containerd/containerd/runtime/v2/runc/options"
35+
"github.com/containerd/containerd/sys"
3536
"github.com/containerd/typeurl"
3637
prototypes "github.com/gogo/protobuf/types"
3738
ver "github.com/opencontainers/image-spec/specs-go"
@@ -422,29 +423,37 @@ func attachExistingIO(response *tasks.GetResponse, ioAttach cio.Attach) (cio.IO,
422423

423424
// loadFifos loads the containers fifos
424425
func loadFifos(response *tasks.GetResponse) *cio.FIFOSet {
425-
path := getFifoDir([]string{
426+
fifos := []string{
426427
response.Process.Stdin,
427428
response.Process.Stdout,
428429
response.Process.Stderr,
429-
})
430+
}
430431
closer := func() error {
431-
return os.RemoveAll(path)
432+
var (
433+
err error
434+
dirs = map[string]struct{}{}
435+
)
436+
for _, fifo := range fifos {
437+
if isFifo, _ := sys.IsFifo(fifo); isFifo {
438+
if rerr := os.Remove(fifo); err == nil {
439+
err = rerr
440+
}
441+
dirs[filepath.Dir(fifo)] = struct{}{}
442+
}
443+
}
444+
for dir := range dirs {
445+
// we ignore errors here because we don't
446+
// want to remove the directory if it isn't
447+
// empty
448+
os.Remove(dir)
449+
}
450+
return err
432451
}
452+
433453
return cio.NewFIFOSet(cio.Config{
434454
Stdin: response.Process.Stdin,
435455
Stdout: response.Process.Stdout,
436456
Stderr: response.Process.Stderr,
437457
Terminal: response.Process.Terminal,
438458
}, closer)
439459
}
440-
441-
// getFifoDir looks for any non-empty path for a stdio fifo
442-
// and returns the dir for where it is located
443-
func getFifoDir(paths []string) string {
444-
for _, p := range paths {
445-
if p != "" {
446-
return filepath.Dir(p)
447-
}
448-
}
449-
return ""
450-
}

0 commit comments

Comments
 (0)