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