remote_daemon_process_unix.go 1.1 KB

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