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