cow.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //go:build windows
  2. package cow
  3. import (
  4. "context"
  5. "io"
  6. "github.com/Microsoft/hcsshim/internal/hcs/schema1"
  7. hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2"
  8. )
  9. // Process is the interface for an OS process running in a container or utility VM.
  10. type Process interface {
  11. // Close releases resources associated with the process and closes the
  12. // writer and readers returned by Stdio. Depending on the implementation,
  13. // this may also terminate the process.
  14. Close() error
  15. // CloseStdin causes the process's stdin handle to receive EOF/EPIPE/whatever
  16. // is appropriate to indicate that no more data is available.
  17. CloseStdin(ctx context.Context) error
  18. // CloseStdout closes the stdout connection to the process. It is used to indicate
  19. // that we are done receiving output on the shim side.
  20. CloseStdout(ctx context.Context) error
  21. // CloseStderr closes the stderr connection to the process. It is used to indicate
  22. // that we are done receiving output on the shim side.
  23. CloseStderr(ctx context.Context) error
  24. // Pid returns the process ID.
  25. Pid() int
  26. // Stdio returns the stdio streams for a process. These may be nil if a stream
  27. // was not requested during CreateProcess.
  28. Stdio() (_ io.Writer, _ io.Reader, _ io.Reader)
  29. // ResizeConsole resizes the virtual terminal associated with the process.
  30. ResizeConsole(ctx context.Context, width, height uint16) error
  31. // Kill sends a SIGKILL or equivalent signal to the process and returns whether
  32. // the signal was delivered. It does not wait for the process to terminate.
  33. Kill(ctx context.Context) (bool, error)
  34. // Signal sends a signal to the process and returns whether the signal was
  35. // delivered. The input is OS specific (either
  36. // guestrequest.SignalProcessOptionsWCOW or
  37. // guestrequest.SignalProcessOptionsLCOW). It does not wait for the process
  38. // to terminate.
  39. Signal(ctx context.Context, options interface{}) (bool, error)
  40. // Wait waits for the process to complete, or for a connection to the process to be
  41. // terminated by some error condition (including calling Close).
  42. Wait() error
  43. // ExitCode returns the exit code of the process. Returns an error if the process is
  44. // not running.
  45. ExitCode() (int, error)
  46. }
  47. // ProcessHost is the interface for creating processes.
  48. type ProcessHost interface {
  49. // CreateProcess creates a process. The configuration is host specific
  50. // (either hcsschema.ProcessParameters or lcow.ProcessParameters).
  51. CreateProcess(ctx context.Context, config interface{}) (Process, error)
  52. // OS returns the host's operating system, "linux" or "windows".
  53. OS() string
  54. // IsOCI specifies whether this is an OCI-compliant process host. If true,
  55. // then the configuration passed to CreateProcess should have an OCI process
  56. // spec (or nil if this is the initial process in an OCI container).
  57. // Otherwise, it should have the HCS-specific process parameters.
  58. IsOCI() bool
  59. }
  60. // Container is the interface for container objects, either running on the host or
  61. // in a utility VM.
  62. type Container interface {
  63. ProcessHost
  64. // Close releases the resources associated with the container. Depending on
  65. // the implementation, this may also terminate the container.
  66. Close() error
  67. // ID returns the container ID.
  68. ID() string
  69. // Properties returns the requested container properties targeting a V1 schema container.
  70. Properties(ctx context.Context, types ...schema1.PropertyType) (*schema1.ContainerProperties, error)
  71. // PropertiesV2 returns the requested container properties targeting a V2 schema container.
  72. PropertiesV2(ctx context.Context, types ...hcsschema.PropertyType) (*hcsschema.Properties, error)
  73. // Start starts a container.
  74. Start(ctx context.Context) error
  75. // Shutdown sends a shutdown request to the container (but does not wait for
  76. // the shutdown to complete).
  77. Shutdown(ctx context.Context) error
  78. // Terminate sends a terminate request to the container (but does not wait
  79. // for the terminate to complete).
  80. Terminate(ctx context.Context) error
  81. // Wait waits for the container to terminate, or for the connection to the
  82. // container to be terminated by some error condition (including calling
  83. // Close).
  84. Wait() error
  85. // WaitChannel returns the wait channel of the container
  86. WaitChannel() <-chan struct{}
  87. // WaitError returns the container termination error.
  88. // This function should only be called after the channel in WaitChannel()
  89. // is closed. Otherwise it is not thread safe.
  90. WaitError() error
  91. // Modify sends a request to modify container resources
  92. Modify(ctx context.Context, config interface{}) error
  93. }