remote_daemon_process_linux.go 1.1 KB

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