1package cow 2 3import ( 4 "context" 5 "io" 6 7 "github.com/Microsoft/hcsshim/internal/schema1" 8 hcsschema "github.com/Microsoft/hcsshim/internal/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 // Pid returns the process ID. 21 Pid() int 22 // Stdio returns the stdio streams for a process. These may be nil if a stream 23 // was not requested during CreateProcess. 24 Stdio() (_ io.Writer, _ io.Reader, _ io.Reader) 25 // ResizeConsole resizes the virtual terminal associated with the process. 26 ResizeConsole(ctx context.Context, width, height uint16) error 27 // Kill sends a SIGKILL or equivalent signal to the process and returns whether 28 // the signal was delivered. It does not wait for the process to terminate. 29 Kill(ctx context.Context) (bool, error) 30 // Signal sends a signal to the process and returns whether the signal was 31 // delivered. The input is OS specific (either 32 // guestrequest.SignalProcessOptionsWCOW or 33 // guestrequest.SignalProcessOptionsLCOW). It does not wait for the process 34 // to terminate. 35 Signal(ctx context.Context, options interface{}) (bool, error) 36 // Wait waits for the process to complete, or for a connection to the process to be 37 // terminated by some error condition (including calling Close). 38 Wait() error 39 // ExitCode returns the exit code of the process. Returns an error if the process is 40 // not running. 41 ExitCode() (int, error) 42} 43 44// ProcessHost is the interface for creating processes. 45type ProcessHost interface { 46 // CreateProcess creates a process. The configuration is host specific 47 // (either hcsschema.ProcessParameters or lcow.ProcessParameters). 48 CreateProcess(ctx context.Context, config interface{}) (Process, error) 49 // OS returns the host's operating system, "linux" or "windows". 50 OS() string 51 // IsOCI specifies whether this is an OCI-compliant process host. If true, 52 // then the configuration passed to CreateProcess should have an OCI process 53 // spec (or nil if this is the initial process in an OCI container). 54 // Otherwise, it should have the HCS-specific process parameters. 55 IsOCI() bool 56} 57 58// Container is the interface for container objects, either running on the host or 59// in a utility VM. 60type Container interface { 61 ProcessHost 62 // Close releases the resources associated with the container. Depending on 63 // the implementation, this may also terminate the container. 64 Close() error 65 // ID returns the container ID. 66 ID() string 67 // Properties returns the requested container properties targeting a V1 schema container. 68 Properties(ctx context.Context, types ...schema1.PropertyType) (*schema1.ContainerProperties, error) 69 // PropertiesV2 returns the requested container properties targeting a V2 schema container. 70 PropertiesV2(ctx context.Context, types ...hcsschema.PropertyType) (*hcsschema.Properties, error) 71 // Start starts a container. 72 Start(ctx context.Context) error 73 // Shutdown sends a shutdown request to the container (but does not wait for 74 // the shutdown to complete). 75 Shutdown(ctx context.Context) error 76 // Terminate sends a terminate request to the container (but does not wait 77 // for the terminate to complete). 78 Terminate(ctx context.Context) error 79 // Wait waits for the container to terminate, or for the connection to the 80 // container to be terminated by some error condition (including calling 81 // Close). 82 Wait() error 83} 84