containerinit

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package containerinit is shared by monolith-init, the PID 1 of container VMs (cmd/monolith-init), and the daemon that runs them: the container's process spec and the logic that turns an image's config into a process (command, user, environment, PATH lookup, signals). Their API is the Agent ttRPC service in agentpb. It has no Linux-only code, so it's tested on the Mac.

Index

Constants

View Source
const (
	ExitInitError     = 125 // the init itself failed (mounts, bad spec)
	ExitNotExecutable = 126
	ExitNotFound      = 127
)

Exit codes the init reports when the process can't run, as Docker does.

View Source
const DefaultPath = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

DefaultPath is used when the image sets no PATH.

View Source
const VsockPort = 1025

VsockPort is the vsock port the init serves the Agent API on.

Variables

This section is empty.

Functions

func Command

func Command(entrypoint, cmd []string, overrideEntrypoint *string, args []string) []string

Command combines an image's entrypoint and cmd with the user's overrides the way `docker run` does: --entrypoint replaces the entrypoint and drops the image's cmd; arguments after the image replace the cmd.

func Getenv

func Getenv(env []string, key string) (string, bool)

Getenv returns KEY's value in env.

func LinuxSignal

func LinuxSignal(s string) (int, error)

LinuxSignal parses a signal as images and `docker kill` give it ("SIGQUIT", "QUIT", "3") into its Linux number.

func LookPath

func LookPath(root, dir, file, pathEnv string) (string, int, error)

LookPath finds file the way execvp does, in the filesystem at root: a name with a slash is used as is (relative to dir), otherwise each PATH entry is tried. It returns the path inside root and the exit code to report if it fails (127 not found, 126 not executable).

func MergeEnv

func MergeEnv(base []string, overrides ...string) []string

MergeEnv appends overrides to base; a later KEY replaces an earlier one in place. An override without "=" (e.g. "-e FOO") is skipped here; the caller fills it from its own environment.

func ProcessEnv

func ProcessEnv(spec Spec, home string) []string

ProcessEnv is the environment the process gets: the spec's, plus PATH, HOSTNAME, HOME and (with a terminal) TERM unless already set.

func ResolvConf

func ResolvConf(pnp string) string

ResolvConf turns the kernel's DHCP results (/proc/net/pnp) into resolv.conf: its nameserver, domain and search lines.

Types

type Cred

type Cred struct {
	UID, GID uint32
	Groups   []uint32 // supplementary groups from /etc/group
	Home     string
}

Cred is who the process runs as.

func ResolveUser

func ResolveUser(root, user string) (Cred, error)

ResolveUser resolves a Docker-style user ("", "name", "uid", "name:group", "uid:gid") against the passwd and group files of the filesystem at root, as runc does: a numeric user that isn't in passwd is still allowed, with gid 0 and home "/".

type Spec

type Spec struct {
	Args     []string `json:"args"`              // command and arguments; Args[0] is looked up in PATH
	Env      []string `json:"env,omitempty"`     // KEY=VALUE, image env then user overrides
	Workdir  string   `json:"workdir,omitempty"` // default "/"
	User     string   `json:"user,omitempty"`    // "", "name", "uid", "name:group" or "uid:gid"
	Hostname string   `json:"hostname,omitempty"`
	TTY      bool     `json:"tty,omitempty"` // run on a terminal (the console), stdin attached
}

Spec describes the container's process. It's saved in the container's config and sent to the init in agentpb.StartRequest.

Directories

Path Synopsis
Code generated by protoc-gen-go-ttrpc.
Code generated by protoc-gen-go-ttrpc.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL