...

Source file src/github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/exec.go

Documentation: github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1

     1  //go:build windows
     2  
     3  package main
     4  
     5  import (
     6  	"context"
     7  
     8  	"github.com/containerd/containerd/errdefs"
     9  	"github.com/containerd/containerd/runtime/v2/task"
    10  	"github.com/pkg/errors"
    11  )
    12  
    13  type shimExecState string
    14  
    15  const (
    16  	shimExecStateCreated shimExecState = "created"
    17  	shimExecStateRunning shimExecState = "running"
    18  	shimExecStateExited  shimExecState = "exited"
    19  )
    20  
    21  // shimExec is an interface that represents a single process created by a user
    22  // within a container (task).
    23  //
    24  // For WCOW process isolated containers the process will be on the same machine
    25  // as this shim.
    26  //
    27  // For WCOW hypervisor isolated or LCOW containers the process will be viewed
    28  // and proxied to the remote UtilityVM hosting the process.
    29  type shimExec interface {
    30  	// ID returns the original id of this exec.
    31  	ID() string
    32  	// Pid returns the pid of the exec process.
    33  	//
    34  	// A call to `Pid` is valid in any `State()`.
    35  	Pid() int
    36  	// State returns the current state of this exec process.
    37  	//
    38  	// A call to `State` is valid in any `State()`.
    39  	State() shimExecState
    40  	// Status returns the current full status of this exec process.
    41  	//
    42  	// A call to `Status` is valid in any `State()`. Note that for `State() ==
    43  	// shimExecStateRunning` this exec process MUST return `ExitStatus=255` and
    44  	// `time.IsZero(ExitedAt)==true` by convention.
    45  	Status() *task.StateResponse
    46  	// Start starts the exec process.
    47  	//
    48  	// If the exec process has already been started this exec MUST return
    49  	// `errdefs.ErrFailedPrecondition`.
    50  	Start(ctx context.Context) error
    51  	// Kill sends `signal` to this exec process.
    52  	//
    53  	// If `State() != shimExecStateRunning` this exec MUST return
    54  	// `errdefs.ErrFailedPrecondition`.
    55  	//
    56  	// If `State() == shimExecStateExited` this exec MUST return `errdefs.ErrNotFound`.
    57  	Kill(ctx context.Context, signal uint32) error
    58  	// ResizePty resizes the tty of this exec process.
    59  	//
    60  	// If this exec is not a tty this exec MUST return
    61  	// `errdefs.ErrFailedPrecondition`.
    62  	//
    63  	// If `State() != shimExecStateRunning` the resize event MUST be ignored and
    64  	// return no error.
    65  	ResizePty(ctx context.Context, width, height uint32) error
    66  	// CloseIO closes `stdin` if open.
    67  	//
    68  	// A call to `CloseIO` is valid in any `State()` and MUST not return an
    69  	// error for duplicate calls.
    70  	CloseIO(ctx context.Context, stdin bool) error
    71  	// Wait waits for this exec process to exit and returns the state of the
    72  	// exit information.
    73  	//
    74  	// A call to `Wait` is valid in any `State()`. Note that if this exec
    75  	// process is already in the `State() == shimExecStateExited` state, `Wait`
    76  	// MUST return immediately with the original exit state.
    77  	Wait() *task.StateResponse
    78  	// ForceExit forcibly terminates the exec, sets the exit status to `status`,
    79  	// and unblocks all waiters.
    80  	//
    81  	// This call is idempotent and safe to call even on an already exited exec
    82  	// in which case it does nothing.
    83  	//
    84  	// `ForceExit` is safe to call in any `State()`.
    85  	ForceExit(ctx context.Context, status int)
    86  }
    87  
    88  func newExecInvalidStateError(tid, eid string, state shimExecState, op string) error {
    89  	return errors.Wrapf(
    90  		errdefs.ErrFailedPrecondition,
    91  		"exec: '%s' in task: '%s' is in invalid state: '%s' for %s",
    92  		eid,
    93  		tid,
    94  		state,
    95  		op)
    96  }
    97  

View as plain text