process_windows.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package libcontainerd
  2. import (
  3. "io"
  4. "github.com/Microsoft/hcsshim"
  5. )
  6. // process keeps the state for both main container process and exec process.
  7. type process struct {
  8. processCommon
  9. // Platform specific fields are below here.
  10. // commandLine is to support returning summary information for docker top
  11. commandLine string
  12. hcsProcess hcsshim.Process
  13. }
  14. func openReaderFromPipe(p io.ReadCloser) io.Reader {
  15. r, w := io.Pipe()
  16. go func() {
  17. if _, err := io.Copy(w, p); err != nil {
  18. r.CloseWithError(err)
  19. }
  20. w.Close()
  21. p.Close()
  22. }()
  23. return r
  24. }
  25. type stdInCloser struct {
  26. io.WriteCloser
  27. hcsshim.Process
  28. }
  29. func createStdInCloser(pipe io.WriteCloser, process hcsshim.Process) *stdInCloser {
  30. return &stdInCloser{
  31. WriteCloser: pipe,
  32. Process: process,
  33. }
  34. }
  35. func (stdin *stdInCloser) Close() error {
  36. if err := stdin.WriteCloser.Close(); err != nil {
  37. return err
  38. }
  39. return stdin.Process.CloseStdin()
  40. }
  41. func (stdin *stdInCloser) Write(p []byte) (n int, err error) {
  42. return stdin.WriteCloser.Write(p)
  43. }