2018-03-19 18:57:30 -04:00
|
|
|
package hcsshim
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"time"
|
|
|
|
|
2018-09-05 14:54:38 -04:00
|
|
|
"github.com/Microsoft/hcsshim/internal/hcs"
|
2018-03-19 18:57:30 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// ContainerError is an error encountered in HCS
|
|
|
|
type process struct {
|
2018-09-05 14:54:38 -04:00
|
|
|
p *hcs.Process
|
2018-03-19 18:57:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Pid returns the process ID of the process within the container.
|
|
|
|
func (process *process) Pid() int {
|
2018-09-05 14:54:38 -04:00
|
|
|
return process.p.Pid()
|
2018-03-19 18:57:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Kill signals the process to terminate but does not wait for it to finish terminating.
|
|
|
|
func (process *process) Kill() error {
|
2018-09-05 14:54:38 -04:00
|
|
|
return convertProcessError(process.p.Kill(), process)
|
2018-03-19 18:57:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Wait waits for the process to exit.
|
|
|
|
func (process *process) Wait() error {
|
2018-09-05 14:54:38 -04:00
|
|
|
return convertProcessError(process.p.Wait(), process)
|
2018-03-19 18:57:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// WaitTimeout waits for the process to exit or the duration to elapse. It returns
|
|
|
|
// false if timeout occurs.
|
|
|
|
func (process *process) WaitTimeout(timeout time.Duration) error {
|
2018-09-05 14:54:38 -04:00
|
|
|
return convertProcessError(process.p.WaitTimeout(timeout), process)
|
2018-03-19 18:57:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ExitCode returns the exit code of the process. The process must have
|
|
|
|
// already terminated.
|
|
|
|
func (process *process) ExitCode() (int, error) {
|
2018-09-05 14:54:38 -04:00
|
|
|
code, err := process.p.ExitCode()
|
2018-03-19 18:57:30 -04:00
|
|
|
if err != nil {
|
2018-09-05 14:54:38 -04:00
|
|
|
err = convertProcessError(err, process)
|
2018-03-19 18:57:30 -04:00
|
|
|
}
|
2018-09-05 14:54:38 -04:00
|
|
|
return code, err
|
2018-03-19 18:57:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ResizeConsole resizes the console of the process.
|
|
|
|
func (process *process) ResizeConsole(width, height uint16) error {
|
2018-09-05 14:54:38 -04:00
|
|
|
return convertProcessError(process.p.ResizeConsole(width, height), process)
|
2018-03-19 18:57:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Stdio returns the stdin, stdout, and stderr pipes, respectively. Closing
|
|
|
|
// these pipes does not close the underlying pipes; it should be possible to
|
|
|
|
// call this multiple times to get multiple interfaces.
|
|
|
|
func (process *process) Stdio() (io.WriteCloser, io.ReadCloser, io.ReadCloser, error) {
|
2018-09-05 14:54:38 -04:00
|
|
|
stdin, stdout, stderr, err := process.p.Stdio()
|
2018-03-19 18:57:30 -04:00
|
|
|
if err != nil {
|
2018-09-05 14:54:38 -04:00
|
|
|
err = convertProcessError(err, process)
|
2018-03-19 18:57:30 -04:00
|
|
|
}
|
2018-09-05 14:54:38 -04:00
|
|
|
return stdin, stdout, stderr, err
|
2018-03-19 18:57:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// CloseStdin closes the write side of the stdin pipe so that the process is
|
|
|
|
// notified on the read side that there is no more data in stdin.
|
|
|
|
func (process *process) CloseStdin() error {
|
2018-09-05 14:54:38 -04:00
|
|
|
return convertProcessError(process.p.CloseStdin(), process)
|
2018-03-19 18:57:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Close cleans up any state associated with the process but does not kill
|
|
|
|
// or wait on it.
|
|
|
|
func (process *process) Close() error {
|
2018-09-05 14:54:38 -04:00
|
|
|
return convertProcessError(process.p.Close(), process)
|
2018-03-19 18:57:30 -04:00
|
|
|
}
|