windows: Create init process with task
This prevents `task.Wait()` to return an error if it is called before the task is started. Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
This commit is contained in:
parent
ad5266456c
commit
cfa87567a0
@ -203,9 +203,9 @@ func TestContainerOutput(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
status := <-statusC
|
status := <-statusC
|
||||||
code, _, _ := status.Result()
|
code, _, err := status.Result()
|
||||||
if code != 0 {
|
if code != 0 {
|
||||||
t.Errorf("expected status 0 but received %d", code)
|
t.Errorf("expected status 0 but received %d: %v", code, err)
|
||||||
}
|
}
|
||||||
if _, err := task.Delete(ctx); err != nil {
|
if _, err := task.Delete(ctx); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
|
@ -52,6 +52,9 @@ func (p *process) State(ctx context.Context) (runtime.State, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *process) Status() runtime.Status {
|
func (p *process) Status() runtime.Status {
|
||||||
|
p.Lock()
|
||||||
|
defer p.Unlock()
|
||||||
|
|
||||||
if p.task.getStatus() == runtime.PausedStatus {
|
if p.task.getStatus() == runtime.PausedStatus {
|
||||||
return runtime.PausedStatus
|
return runtime.PausedStatus
|
||||||
}
|
}
|
||||||
@ -71,15 +74,24 @@ func (p *process) Status() runtime.Status {
|
|||||||
|
|
||||||
func (p *process) Kill(ctx context.Context, sig uint32, all bool) error {
|
func (p *process) Kill(ctx context.Context, sig uint32, all bool) error {
|
||||||
// On windows all signals kill the process
|
// On windows all signals kill the process
|
||||||
|
if p.Status() == runtime.CreatedStatus {
|
||||||
|
return errors.Wrap(errdefs.ErrFailedPrecondition, "process was not started")
|
||||||
|
}
|
||||||
return errors.Wrap(p.hcs.Kill(), "failed to kill process")
|
return errors.Wrap(p.hcs.Kill(), "failed to kill process")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *process) ResizePty(ctx context.Context, size runtime.ConsoleSize) error {
|
func (p *process) ResizePty(ctx context.Context, size runtime.ConsoleSize) error {
|
||||||
|
if p.Status() == runtime.CreatedStatus {
|
||||||
|
return errors.Wrap(errdefs.ErrFailedPrecondition, "process was not started")
|
||||||
|
}
|
||||||
err := p.hcs.ResizeConsole(uint16(size.Width), uint16(size.Height))
|
err := p.hcs.ResizeConsole(uint16(size.Width), uint16(size.Height))
|
||||||
return errors.Wrap(err, "failed to resize process console")
|
return errors.Wrap(err, "failed to resize process console")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *process) CloseIO(ctx context.Context) error {
|
func (p *process) CloseIO(ctx context.Context) error {
|
||||||
|
if p.Status() == runtime.CreatedStatus {
|
||||||
|
return errors.Wrap(errdefs.ErrFailedPrecondition, "process was not started")
|
||||||
|
}
|
||||||
return errors.Wrap(p.hcs.CloseStdin(), "failed to close stdin")
|
return errors.Wrap(p.hcs.CloseStdin(), "failed to close stdin")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -304,6 +304,11 @@ func (r *windowsRuntime) newTask(ctx context.Context, namespace, id string, spec
|
|||||||
hcsContainer: ctr,
|
hcsContainer: ctr,
|
||||||
terminateDuration: createOpts.TerminateDuration,
|
terminateDuration: createOpts.TerminateDuration,
|
||||||
}
|
}
|
||||||
|
// Create the new process but don't start it
|
||||||
|
pconf := newWindowsProcessConfig(t.spec.Process, t.io)
|
||||||
|
if _, err = t.newProcess(ctx, t.id, pconf, t.io); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
r.tasks.Add(ctx, t)
|
r.tasks.Add(ctx, t)
|
||||||
|
|
||||||
var rootfs []*containerdtypes.Mount
|
var rootfs []*containerdtypes.Mount
|
||||||
|
@ -111,17 +111,16 @@ func (t *task) Info() runtime.TaskInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *task) Start(ctx context.Context) error {
|
func (t *task) Start(ctx context.Context) error {
|
||||||
if p := t.getProcess(t.id); p != nil {
|
p := t.getProcess(t.id)
|
||||||
return errors.Wrap(errdefs.ErrFailedPrecondition, "task already started")
|
if p == nil {
|
||||||
|
panic("init process is missing")
|
||||||
}
|
}
|
||||||
|
|
||||||
conf := newWindowsProcessConfig(t.spec.Process, t.io)
|
if p.Status() != runtime.CreatedStatus {
|
||||||
p, err := t.newProcess(ctx, t.id, conf, t.io)
|
return errors.Wrap(errdefs.ErrFailedPrecondition, "process was already started")
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := p.Start(ctx); err != nil {
|
if err := p.Start(ctx); err != nil {
|
||||||
t.removeProcess(t.id)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
t.publisher.Publish(ctx,
|
t.publisher.Publish(ctx,
|
||||||
|
Loading…
Reference in New Issue
Block a user