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 <estesp@linux.vnet.ibm.com>
This commit is contained in:
parent
0c78dacbc5
commit
78ab1d13d2
39
container.go
39
container.go
@ -32,6 +32,7 @@ import (
|
||||
"github.com/containerd/containerd/images"
|
||||
"github.com/containerd/containerd/oci"
|
||||
"github.com/containerd/containerd/runtime/v2/runc/options"
|
||||
"github.com/containerd/containerd/sys"
|
||||
"github.com/containerd/typeurl"
|
||||
prototypes "github.com/gogo/protobuf/types"
|
||||
ver "github.com/opencontainers/image-spec/specs-go"
|
||||
@ -422,14 +423,33 @@ func attachExistingIO(response *tasks.GetResponse, ioAttach cio.Attach) (cio.IO,
|
||||
|
||||
// loadFifos loads the containers fifos
|
||||
func loadFifos(response *tasks.GetResponse) *cio.FIFOSet {
|
||||
path := getFifoDir([]string{
|
||||
fifos := []string{
|
||||
response.Process.Stdin,
|
||||
response.Process.Stdout,
|
||||
response.Process.Stderr,
|
||||
})
|
||||
closer := func() error {
|
||||
return os.RemoveAll(path)
|
||||
}
|
||||
closer := func() error {
|
||||
var (
|
||||
err error
|
||||
dirs = map[string]struct{}{}
|
||||
)
|
||||
for _, fifo := range fifos {
|
||||
if isFifo, _ := sys.IsFifo(fifo); isFifo {
|
||||
if rerr := os.Remove(fifo); err == nil {
|
||||
err = rerr
|
||||
}
|
||||
dirs[filepath.Dir(fifo)] = struct{}{}
|
||||
}
|
||||
}
|
||||
for dir := range dirs {
|
||||
// we ignore errors here because we don't
|
||||
// want to remove the directory if it isn't
|
||||
// empty
|
||||
os.Remove(dir)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
return cio.NewFIFOSet(cio.Config{
|
||||
Stdin: response.Process.Stdin,
|
||||
Stdout: response.Process.Stdout,
|
||||
@ -437,14 +457,3 @@ func loadFifos(response *tasks.GetResponse) *cio.FIFOSet {
|
||||
Terminal: response.Process.Terminal,
|
||||
}, closer)
|
||||
}
|
||||
|
||||
// getFifoDir looks for any non-empty path for a stdio fifo
|
||||
// and returns the dir for where it is located
|
||||
func getFifoDir(paths []string) string {
|
||||
for _, p := range paths {
|
||||
if p != "" {
|
||||
return filepath.Dir(p)
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user