From e04dca2bd67f2f25d5616731742ede6b81082c69 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Mon, 18 Apr 2016 11:01:02 -0700 Subject: [PATCH] Clean up exec fifos on process exit Signed-off-by: Tonis Tiigi (cherry picked from commit 84d170129a19855829d282e5416ce08ddb2edbd6) --- libcontainerd/container_linux.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/libcontainerd/container_linux.go b/libcontainerd/container_linux.go index 631b225e68..2eea497caf 100644 --- a/libcontainerd/container_linux.go +++ b/libcontainerd/container_linux.go @@ -36,6 +36,19 @@ func (ctr *container) clean() error { return nil } +// cleanProcess removes the fifos used by an additional process. +// Caller needs to lock container ID before calling this method. +func (ctr *container) cleanProcess(id string) { + if p, ok := ctr.processes[id]; ok { + for _, i := range []int{syscall.Stdin, syscall.Stdout, syscall.Stderr} { + if err := os.Remove(p.fifo(i)); err != nil { + logrus.Warnf("failed to remove %v for process %v: %v", p.fifo(i), id, err) + } + } + } + delete(ctr.processes, id) +} + func (ctr *container) spec() (*specs.Spec, error) { var spec specs.Spec dt, err := ioutil.ReadFile(filepath.Join(ctr.dir, configFilename)) @@ -142,11 +155,14 @@ func (ctr *container) handleEvent(e *containerd.Event) error { // Remove process from list if we have exited // We need to do so here in case the Message Handler decides to restart it. - if st.State == StateExit { + switch st.State { + case StateExit: if os.Getenv("LIBCONTAINERD_NOCLEAN") != "1" { ctr.clean() } ctr.client.deleteContainer(e.Id) + case StateExitProcess: + ctr.cleanProcess(st.ProcessID) } ctr.client.q.append(e.Id, func() { if err := ctr.client.backend.StateChanged(e.Id, st); err != nil {