process_windows.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package libcontainerd
  2. import (
  3. "io"
  4. "sync"
  5. "github.com/Microsoft/hcsshim"
  6. "github.com/docker/docker/pkg/ioutils"
  7. )
  8. // process keeps the state for both main container process and exec process.
  9. type process struct {
  10. processCommon
  11. // Platform specific fields are below here.
  12. // commandLine is to support returning summary information for docker top
  13. commandLine string
  14. hcsProcess hcsshim.Process
  15. }
  16. type autoClosingReader struct {
  17. io.ReadCloser
  18. sync.Once
  19. }
  20. func (r *autoClosingReader) Read(b []byte) (n int, err error) {
  21. n, err = r.ReadCloser.Read(b)
  22. if err == io.EOF {
  23. r.Once.Do(func() { r.ReadCloser.Close() })
  24. }
  25. return
  26. }
  27. func createStdInCloser(pipe io.WriteCloser, process hcsshim.Process) io.WriteCloser {
  28. return ioutils.NewWriteCloserWrapper(pipe, func() error {
  29. if err := pipe.Close(); err != nil {
  30. return err
  31. }
  32. err := process.CloseStdin()
  33. if err != nil && !hcsshim.IsNotExist(err) && !hcsshim.IsAlreadyClosed(err) {
  34. // This error will occur if the compute system is currently shutting down
  35. if perr, ok := err.(*hcsshim.ProcessError); ok && perr.Err != hcsshim.ErrVmcomputeOperationInvalidState {
  36. return err
  37. }
  38. }
  39. return nil
  40. })
  41. }