github.com/shishir-a412ed/docker@v1.3.2-0.20180103180333-fda904911d87/libcontainerd/remote_daemon_process_linux.go (about)

     1  package libcontainerd
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  
     7  	"github.com/pkg/errors"
     8  	"golang.org/x/sys/unix"
     9  )
    10  
    11  var fdNames = map[int]string{
    12  	unix.Stdin:  "stdin",
    13  	unix.Stdout: "stdout",
    14  	unix.Stderr: "stderr",
    15  }
    16  
    17  func (p *process) pipeName(index int) string {
    18  	return filepath.Join(p.root, p.id+"-"+fdNames[index])
    19  }
    20  
    21  func (p *process) IOPaths() (string, string, string) {
    22  	var (
    23  		stdin  = p.pipeName(unix.Stdin)
    24  		stdout = p.pipeName(unix.Stdout)
    25  		stderr = p.pipeName(unix.Stderr)
    26  	)
    27  	// TODO: debug why we're having zombies when I don't unset those
    28  	if p.io.Stdin == nil {
    29  		stdin = ""
    30  	}
    31  	if p.io.Stderr == nil {
    32  		stderr = ""
    33  	}
    34  	return stdin, stdout, stderr
    35  }
    36  
    37  func (p *process) Cleanup() error {
    38  	var retErr error
    39  
    40  	// Ensure everything was closed
    41  	p.CloseIO()
    42  
    43  	for _, i := range [3]string{
    44  		p.pipeName(unix.Stdin),
    45  		p.pipeName(unix.Stdout),
    46  		p.pipeName(unix.Stderr),
    47  	} {
    48  		err := os.Remove(i)
    49  		if err != nil {
    50  			if retErr == nil {
    51  				retErr = errors.Wrapf(err, "failed to remove %s", i)
    52  			} else {
    53  				retErr = errors.Wrapf(retErr, "failed to remove %s", i)
    54  			}
    55  		}
    56  	}
    57  
    58  	return retErr
    59  }