process_windows.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. hcsProcess hcsshim.Process
  13. }
  14. type autoClosingReader struct {
  15. io.ReadCloser
  16. sync.Once
  17. }
  18. func (r *autoClosingReader) Read(b []byte) (n int, err error) {
  19. n, err = r.ReadCloser.Read(b)
  20. if err == io.EOF {
  21. r.Once.Do(func() { r.ReadCloser.Close() })
  22. }
  23. return
  24. }
  25. func createStdInCloser(pipe io.WriteCloser, process hcsshim.Process) io.WriteCloser {
  26. return ioutils.NewWriteCloserWrapper(pipe, func() error {
  27. if err := pipe.Close(); err != nil {
  28. return err
  29. }
  30. err := process.CloseStdin()
  31. if err != nil && !hcsshim.IsNotExist(err) && !hcsshim.IsAlreadyClosed(err) {
  32. // This error will occur if the compute system is currently shutting down
  33. if perr, ok := err.(*hcsshim.ProcessError); ok && perr.Err != hcsshim.ErrVmcomputeOperationInvalidState {
  34. return err
  35. }
  36. }
  37. return nil
  38. })
  39. }