@@ -68,6 +68,10 @@ type container struct {
|
||||
sendEvent eventCallback
|
||||
}
|
||||
|
||||
func (c *container) ID() string {
|
||||
return c.ctr.ID()
|
||||
}
|
||||
|
||||
func (c *container) Info() runtime.TaskInfo {
|
||||
return runtime.TaskInfo{
|
||||
ID: c.ctr.ID(),
|
||||
@@ -122,14 +126,23 @@ func (c *container) State(ctx context.Context) (runtime.State, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *container) Kill(ctx context.Context, signal uint32, pid uint32, all bool) error {
|
||||
func (c *container) Kill(ctx context.Context, signal uint32, all bool) error {
|
||||
if winsys.Signal(signal) == winsys.SIGKILL {
|
||||
return c.ctr.Kill(ctx)
|
||||
}
|
||||
return c.ctr.Stop(ctx)
|
||||
}
|
||||
|
||||
func (c *container) Exec(ctx context.Context, opts runtime.ExecOpts) (runtime.Process, error) {
|
||||
func (c *container) Process(ctx context.Context, id string) (runtime.Process, error) {
|
||||
for _, p := range c.ctr.Processes() {
|
||||
if p.ID() == id {
|
||||
return &process{p}, nil
|
||||
}
|
||||
}
|
||||
return nil, errors.Errorf("process %s not found", id)
|
||||
}
|
||||
|
||||
func (c *container) Exec(ctx context.Context, id string, opts runtime.ExecOpts) (runtime.Process, error) {
|
||||
if c.ctr.Pid() == 0 {
|
||||
return nil, ErrLoadedContainer
|
||||
}
|
||||
@@ -144,7 +157,7 @@ func (c *container) Exec(ctx context.Context, opts runtime.ExecOpts) (runtime.Pr
|
||||
return nil, errors.Wrap(err, "failed to unmarshal oci spec")
|
||||
}
|
||||
|
||||
p, err := c.ctr.AddProcess(ctx, &procSpec, pio)
|
||||
p, err := c.ctr.AddProcess(ctx, id, &procSpec, pio)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -160,12 +173,12 @@ func (c *container) Exec(ctx context.Context, opts runtime.ExecOpts) (runtime.Pr
|
||||
return &process{p}, nil
|
||||
}
|
||||
|
||||
func (c *container) CloseIO(ctx context.Context, pid uint32) error {
|
||||
return c.ctr.CloseIO(ctx, pid)
|
||||
func (c *container) CloseIO(ctx context.Context) error {
|
||||
return c.ctr.CloseIO(ctx)
|
||||
}
|
||||
|
||||
func (c *container) ResizePty(ctx context.Context, pid uint32, size runtime.ConsoleSize) error {
|
||||
return c.ctr.ResizePty(ctx, pid, size)
|
||||
func (c *container) ResizePty(ctx context.Context, size runtime.ConsoleSize) error {
|
||||
return c.ctr.ResizePty(ctx, size)
|
||||
}
|
||||
|
||||
func (c *container) Status() runtime.Status {
|
||||
@@ -192,16 +205,16 @@ func (c *container) Checkpoint(ctx context.Context, _ string, _ *types.Any) erro
|
||||
return fmt.Errorf("Windows containers do not support checkpoint")
|
||||
}
|
||||
|
||||
func (c *container) DeleteProcess(ctx context.Context, pid uint32) (*runtime.Exit, error) {
|
||||
func (c *container) DeleteProcess(ctx context.Context, id string) (*runtime.Exit, error) {
|
||||
var process *hcs.Process
|
||||
for _, p := range c.ctr.Processes() {
|
||||
if p.Pid() == pid {
|
||||
if p.ID() == id {
|
||||
process = p
|
||||
break
|
||||
}
|
||||
}
|
||||
if process == nil {
|
||||
return nil, fmt.Errorf("process %d not found", pid)
|
||||
return nil, fmt.Errorf("process %s not found", id)
|
||||
}
|
||||
ec, err := process.ExitCode()
|
||||
if err != nil {
|
||||
|
||||
@@ -172,7 +172,7 @@ func (c *Container) Processes() []*Process {
|
||||
}
|
||||
|
||||
func (c *Container) Start(ctx context.Context) error {
|
||||
_, err := c.addProcess(ctx, c.spec.Process, c.io)
|
||||
_, err := c.addProcess(ctx, c.id, c.spec.Process, c.io)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -199,35 +199,35 @@ func (c *Container) Stop(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Container) CloseIO(ctx context.Context, pid uint32) error {
|
||||
func (c *Container) CloseIO(ctx context.Context) error {
|
||||
var proc *Process
|
||||
c.Lock()
|
||||
for _, p := range c.processes {
|
||||
if p.Pid() == pid {
|
||||
if p.id == c.id {
|
||||
proc = p
|
||||
break
|
||||
}
|
||||
}
|
||||
c.Unlock()
|
||||
if proc == nil {
|
||||
return errors.Errorf("no such process %v", pid)
|
||||
return errors.Errorf("no such process %s", c.id)
|
||||
}
|
||||
|
||||
return proc.CloseStdin()
|
||||
}
|
||||
|
||||
func (c *Container) ResizePty(ctx context.Context, pid uint32, size runtime.ConsoleSize) error {
|
||||
func (c *Container) ResizePty(ctx context.Context, size runtime.ConsoleSize) error {
|
||||
var proc *Process
|
||||
c.Lock()
|
||||
for _, p := range c.processes {
|
||||
if p.Pid() == pid {
|
||||
if p.id == c.id {
|
||||
proc = p
|
||||
break
|
||||
}
|
||||
}
|
||||
c.Unlock()
|
||||
if proc == nil {
|
||||
return errors.Errorf("no such process %v", pid)
|
||||
return errors.Errorf("no such process %s", c.id)
|
||||
}
|
||||
|
||||
return proc.ResizeConsole(uint16(size.Width), uint16(size.Height))
|
||||
@@ -303,15 +303,14 @@ func (c *Container) GetConfiguration() Configuration {
|
||||
return c.conf
|
||||
}
|
||||
|
||||
func (c *Container) AddProcess(ctx context.Context, spec *specs.Process, io *IO) (*Process, error) {
|
||||
func (c *Container) AddProcess(ctx context.Context, id string, spec *specs.Process, io *IO) (*Process, error) {
|
||||
if len(c.processes) == 0 {
|
||||
return nil, errors.New("container not started")
|
||||
}
|
||||
|
||||
return c.addProcess(ctx, spec, io)
|
||||
return c.addProcess(ctx, id, spec, io)
|
||||
}
|
||||
|
||||
func (c *Container) addProcess(ctx context.Context, spec *specs.Process, pio *IO) (*Process, error) {
|
||||
func (c *Container) addProcess(ctx context.Context, id string, spec *specs.Process, pio *IO) (*Process, error) {
|
||||
// If we don't have a process yet, reused the container pid
|
||||
var pid uint32
|
||||
if len(c.processes) == 0 {
|
||||
@@ -388,6 +387,7 @@ func (c *Container) addProcess(ctx context.Context, spec *specs.Process, pio *IO
|
||||
}
|
||||
|
||||
p := &Process{
|
||||
id: id,
|
||||
Process: proc,
|
||||
pid: pid,
|
||||
io: pio,
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
type Process struct {
|
||||
hcsshim.Process
|
||||
|
||||
id string
|
||||
pid uint32
|
||||
io *IO
|
||||
ec uint32
|
||||
@@ -22,6 +23,10 @@ type Process struct {
|
||||
ecSync chan struct{}
|
||||
}
|
||||
|
||||
func (p *Process) ID() string {
|
||||
return p.id
|
||||
}
|
||||
|
||||
func (p *Process) Pid() uint32 {
|
||||
return p.pid
|
||||
}
|
||||
|
||||
@@ -32,3 +32,11 @@ func (p *process) Status() runtime.Status {
|
||||
func (p *process) Pid() uint32 {
|
||||
return p.Process.Pid()
|
||||
}
|
||||
|
||||
func (p *process) CloseIO(ctx context.Context) error {
|
||||
return p.Process.CloseStdin()
|
||||
}
|
||||
|
||||
func (p *process) ResizePty(ctx context.Context, size runtime.ConsoleSize) error {
|
||||
return p.Process.ResizeConsole(uint16(size.Width), uint16(size.Height))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user