Skip to content

Commit fd2c9e3

Browse files
estespthaJeztah
authored andcommitted
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]> (cherry picked from commit 78ab1d1) Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent ab89e63 commit fd2c9e3

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"
@@ -411,29 +412,37 @@ func attachExistingIO(response *tasks.GetResponse, ioAttach cio.Attach) (cio.IO,
411412

412413
// loadFifos loads the containers fifos
413414
func loadFifos(response *tasks.GetResponse) *cio.FIFOSet {
414-
path := getFifoDir([]string{
415+
fifos := []string{
415416
response.Process.Stdin,
416417
response.Process.Stdout,
417418
response.Process.Stderr,
418-
})
419+
}
419420
closer := func() error {
420-
return os.RemoveAll(path)
421+
var (
422+
err error
423+
dirs = map[string]struct{}{}
424+
)
425+
for _, fifo := range fifos {
426+
if isFifo, _ := sys.IsFifo(fifo); isFifo {
427+
if rerr := os.Remove(fifo); err == nil {
428+
err = rerr
429+
}
430+
dirs[filepath.Dir(fifo)] = struct{}{}
431+
}
432+
}
433+
for dir := range dirs {
434+
// we ignore errors here because we don't
435+
// want to remove the directory if it isn't
436+
// empty
437+
os.Remove(dir)
438+
}
439+
return err
421440
}
441+
422442
return cio.NewFIFOSet(cio.Config{
423443
Stdin: response.Process.Stdin,
424444
Stdout: response.Process.Stdout,
425445
Stderr: response.Process.Stderr,
426446
Terminal: response.Process.Terminal,
427447
}, closer)
428448
}
429-
430-
// getFifoDir looks for any non-empty path for a stdio fifo
431-
// and returns the dir for where it is located
432-
func getFifoDir(paths []string) string {
433-
for _, p := range paths {
434-
if p != "" {
435-
return filepath.Dir(p)
436-
}
437-
}
438-
return ""
439-
}

0 commit comments

Comments
 (0)