...

Source file src/github.com/Microsoft/hcsshim/internal/runhcs/container.go

Documentation: github.com/Microsoft/hcsshim/internal/runhcs

     1  //go:build windows
     2  
     3  package runhcs
     4  
     5  import (
     6  	"bytes"
     7  	"errors"
     8  	"fmt"
     9  	"io"
    10  	"os"
    11  	"syscall"
    12  	"time"
    13  
    14  	"github.com/Microsoft/go-winio/pkg/guid"
    15  )
    16  
    17  // ContainerState represents the platform agnostic pieces relating to a
    18  // running container's status and state
    19  type ContainerState struct {
    20  	// Version is the OCI version for the container
    21  	Version string `json:"ociVersion"`
    22  	// ID is the container ID
    23  	ID string `json:"id"`
    24  	// InitProcessPid is the init process id in the parent namespace
    25  	InitProcessPid int `json:"pid"`
    26  	// Status is the current status of the container, running, paused, ...
    27  	Status string `json:"status"`
    28  	// Bundle is the path on the filesystem to the bundle
    29  	Bundle string `json:"bundle"`
    30  	// Rootfs is a path to a directory containing the container's root filesystem.
    31  	Rootfs string `json:"rootfs"`
    32  	// Created is the unix timestamp for the creation time of the container in UTC
    33  	Created time.Time `json:"created"`
    34  	// Annotations is the user defined annotations added to the config.
    35  	Annotations map[string]string `json:"annotations,omitempty"`
    36  	// The owner of the state directory (the owner of the container).
    37  	Owner string `json:"owner"`
    38  }
    39  
    40  // GetErrorFromPipe returns reads from `pipe` and verifies if the operation
    41  // returned success or error. If error converts that to an error and returns. If
    42  // `p` is not nill will issue a `Kill` and `Wait` for exit.
    43  func GetErrorFromPipe(pipe io.Reader, p *os.Process) error {
    44  	serr, err := io.ReadAll(pipe)
    45  	if err != nil {
    46  		return err
    47  	}
    48  
    49  	if bytes.Equal(serr, ShimSuccess) {
    50  		return nil
    51  	}
    52  
    53  	extra := ""
    54  	if p != nil {
    55  		_ = p.Kill()
    56  		state, err := p.Wait()
    57  		if err != nil {
    58  			panic(err)
    59  		}
    60  		extra = fmt.Sprintf(", exit code %d", state.Sys().(syscall.WaitStatus).ExitCode)
    61  	}
    62  	if len(serr) == 0 {
    63  		return fmt.Errorf("unknown shim failure%s", extra)
    64  	}
    65  
    66  	return errors.New(string(serr))
    67  }
    68  
    69  // VMPipePath returns the named pipe path for the vm shim.
    70  func VMPipePath(hostUniqueID guid.GUID) string {
    71  	return SafePipePath("runhcs-vm-" + hostUniqueID.String())
    72  }
    73  

View as plain text