@@ -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
413414func 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