demo

package
v0.2.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2026 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Overview

Package demo owns the disposable installed local measurement.

Index

Constants

View Source
const OpenWithoutWaiting = syscall.O_NONBLOCK

OpenWithoutWaiting is the open flag that keeps opening a named pipe from waiting until somebody opens the other end. A privileged command that opens what it finds in a directory another account writes needs it, or that account can stop the command indefinitely by leaving a pipe there.

Variables

View Source
var ErrForcedKill = errors.New("demo child required forced termination")

ErrForcedKill distinguishes cleanup that required SIGKILL from graceful exit.

Functions

func BootstrapFresh

func BootstrapFresh(ctx context.Context, role SchemaRole, path string) error

BootstrapFresh applies the canonical migrations to a new, private database. The caller must own the mode-0700 parent and keep it exclusively under its control until this function returns. Existing databases are never upgraded.

func CheckSchema

func CheckSchema(ctx context.Context, role SchemaRole, path string) error

CheckSchema verifies an existing database against the schema versions this package's services support. Local services never upgrade a database in place, so an unsupported one is reported instead of being migrated.

func DefaultLocalStateDir

func DefaultLocalStateDir() (string, error)

DefaultLocalStateDir follows the XDG state convention without depending on the current working directory.

func DispatcherConfiguration

func DispatcherConfiguration(version, database string) map[string]any

DispatcherConfiguration returns the generated dispatcher configuration for a database path. Callers may override the server ports before writing it.

func DispatcherUp

func DispatcherUp(ctx context.Context, assets Assets, options RoleOptions) error

func ExecutorConfiguration

func ExecutorConfiguration(version, executorID, database string, dispatcher readiness.Record) map[string]any

ExecutorConfiguration returns the generated executor configuration for one executor identity, database and dispatcher control record.

func ExecutorUp

func ExecutorUp(ctx context.Context, assets Assets, options RoleOptions) error

func FileNames

func FileNames(info fs.FileInfo) (uint64, bool)

FileNames reports how many names a file has. A regular file with more than one is reachable under a name this caller never created and may not be able to see, so ownership applied to it is applied to that name too.

func PrepareRoleDatabase

func PrepareRoleDatabase(ctx context.Context, role SchemaRole, dir string) (path string, created bool, err error)

PrepareRoleDatabase creates the role's database on first use and verifies an existing one against the schema versions this build serves. It never migrates: an unsupported database is reported with the action to take. It reports whether this call is the one that created the database. The caller owns the mode-0700 parent directory for the whole call.

Whether creating is allowed is the bootstrap's own decision, not a guess made here: it requires a mode-0700 parent this administrator owns, which is a directory an installation has just made and never one it handed to the service account when it last finished. So an installation interrupted before its database existed can be completed by the next one, a finished directory can have nothing created in it, and no account that could replace the name in between has the directory to do it in.

func ReadReadyRecord

func ReadReadyRecord(path string, pid int, executorID string) (readiness.Record, error)

ReadReadyRecord reads one published readiness record and checks it against the process that was supposed to publish it. The record is evidence that the daemon reached its own ready point: an existing process, or a service manager that merely created one, proves nothing on its own. A missing record is reported as os.ErrNotExist so a caller can keep waiting for it.

func RoleDatabase

func RoleDatabase(dir string, role SchemaRole) string

RoleDatabase names the database file a role keeps in its state directory.

func Up

func Up(ctx context.Context, assets Assets, options LocalOptions) error

Up runs an installed loopback environment until cancellation. Databases and identity survive clean shutdown; environment.json exists only while ready. A canceled context means a normal stop, provided child cleanup succeeds.

func ValidateControlAddress

func ValidateControlAddress(address string) error

ValidateControlAddress accepts the literal-loopback host:port spelling the generated configurations use for the local control plane.

func WriteConfig

func WriteConfig(path string, config map[string]any) error

WriteConfig writes a generated configuration to an absent path, mode 0600.

Types

type Assets

type Assets struct {
	Root, CLI, Dispatcher, Executor, Guest string
	Manifest                               Manifest
}

func ResolveAssets

func ResolveAssets(executable string) (Assets, error)

ResolveAssets follows the entry-point symlink once, then verifies the exact installed payload. Neither PATH nor the current directory supplies assets.

type Child

type Child struct {
	// contains filtered or unexported fields
}

Child owns one process group and exactly one cmd.Wait invocation. Closing done publishes waitErr and also joins os/exec's output-copy goroutines.

func StartChild

func StartChild(spec ChildSpec) (*Child, error)

func (*Child) CleanupComplete

func (c *Child) CleanupComplete() bool

CleanupComplete proves both the controller and direct-child reaper joined, and that the entire tracked process group disappeared. Cache observed group removal so a future unrelated reuse of this numeric PGID cannot change it.

func (*Child) Done

func (c *Child) Done() <-chan struct{}

func (*Child) PID

func (c *Child) PID() int

func (*Child) Stop

func (c *Child) Stop(ctx context.Context) error

Stop starts teardown once. The first caller owns its bounded controller; other callers can join it with their own context. No stop goroutine outlives its caller. Done alone describes the direct child, not its process group.

func (*Child) Wait

func (c *Child) Wait(ctx context.Context) error

type ChildSpec

type ChildSpec struct {
	Path, Dir      string
	Args, Env      []string
	Stdout, Stderr io.Writer
}

type LocalEnvironment

type LocalEnvironment struct {
	State      string `json:"state"`
	Endpoint   string `json:"endpoint"`
	ExecutorID string `json:"executor_id"`
	StateDir   string `json:"state_dir"`
}

LocalEnvironment describes the currently running local services.

type LocalOptions

type LocalOptions struct {
	StateDir string
	Port     int
	Ready    func(LocalEnvironment) error
}

type Manifest

type Manifest = artifact.Manifest

type Result

type Result struct {
	Version    string `json:"version"`
	ExecutorID string `json:"executor_id"`
	RunID      string `json:"run_id"`
	Response   string `json:"response"`
	State      string `json:"state"`
	Cleanup    string `json:"cleanup"`
}

func Run

func Run(ctx context.Context, assets Assets) (Result, error)

Run verifies the installed assets, runs one wallet-free local measurement, and joins all owned processes and callbacks before reporting success.

type RoleEnvironment

type RoleEnvironment struct {
	State        string `json:"state"`
	Role         string `json:"role"`
	Name         string `json:"name"`
	Endpoint     string `json:"endpoint"`
	GRPCAddress  string `json:"grpc_address,omitempty"`
	YamuxAddress string `json:"yamux_address,omitempty"`
	ExecutorID   string `json:"executor_id,omitempty"`
	StateDir     string `json:"state_dir"`
}

RoleEnvironment describes one independently running local service.

type RoleOptions

type RoleOptions struct {
	Name, StateDir string
	Port, GRPCPort int
	Dispatcher     connections.Profile
	Ready          func(RoleEnvironment) error
}

type RoleState

type RoleState struct {
	SchemaVersion int        `json:"schema_version"`
	Version       string     `json:"version"`
	SourceSHA     string     `json:"source_sha"`
	Identity      string     `json:"identity"`
	Role          SchemaRole `json:"role"`
	// EarlierIdentity is the key earlier builds wrote the identity under. It
	// is read when the file carries no identity value and is never written.
	EarlierIdentity string `json:"executor_id,omitempty"`
}

RoleState is the persistent identity of one managed role directory. It pins the installed version that created the directory, so a payload the databases were never served by cannot silently adopt them.

func EnsureRoleState

func EnsureRoleState(dir string, role SchemaRole, manifest Manifest) (RoleState, error)

EnsureRoleState reads, or on first use creates, the persistent identity of a role state directory. The caller owns the mode-0700 directory and keeps it under its own control for the duration of the call.

type SchemaRole

type SchemaRole string
const (
	DispatcherSchema SchemaRole = "dispatcher"
	ExecutorSchema   SchemaRole = "executor"
)

Directories

Path Synopsis
Package service installs a verified Debuglet role payload as a service the host's service manager supervises.
Package service installs a verified Debuglet role payload as a service the host's service manager supervises.

Jump to

Keyboard shortcuts

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