program

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 14 Imported by: 0 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 program starts and owns the executables a package declares. It knows no protocol: a caller receives the child's standard streams and speaks whatever the program speaks.

Index

Constants

This section is empty.

Variables

View Source
var ErrBusy = errors.New("programs are busy")

ErrBusy reports that an owner's programs are all in use.

View Source
var ErrNotInstalled = errors.New("program is not installed")

ErrNotInstalled reports that the command is not on the search path.

Functions

func Inherited

func Inherited(name string) bool

Inherited reports whether the Node owns name, so a declaration cannot set it.

func Resolve

func Resolve(name string, environment map[string]string) (string, error)

Resolve finds an executable by name on the PATH of environment. A name with a separator is refused, so a declaration never names a path.

func StartGroup

func StartGroup(command *exec.Cmd) (func(), error)

StartGroup starts command as the leader of its own process group (a job object on Windows) and returns the function that kills the whole group.

Types

type Entry

type Entry struct {
	Process *Process
	Value   any
	// contains filtered or unexported fields
}

Entry is one running program and the state its user keeps with it.

type File

type File struct{ Path, Content string }

File is written into the program's directory before it starts.

type Pool

type Pool struct {
	Limit int
	Idle  time.Duration
	// contains filtered or unexported fields
}

Pool bounds and reaps the running programs of every owner (a package). A caller attaches its own protocol state to an entry as Value.

func NewPool

func NewPool(limit int, idle time.Duration) *Pool

func (*Pool) Close

func (pool *Pool) Close()

Close kills every program and refuses new ones.

func (*Pool) Invalidate

func (pool *Pool) Invalidate(owner string)

Invalidate kills every program of owner, in use or not.

func (*Pool) Lease

func (pool *Pool) Lease(owner string, rank func(*Entry) int, start func() (*Process, any, error)) (*Entry, error)

Lease returns the idle program of owner that rank values highest above zero, else starts one. At the limit it replaces the owner's longest-idle program; when every one is in use it fails with ErrBusy. The caller must Release the entry.

func (*Pool) Release

func (pool *Pool) Release(entry *Entry, keep bool)

Release returns a leased entry. A program that is not kept is killed.

type Process

type Process struct {
	Stdin  io.WriteCloser
	Stdout io.Reader
	// contains filtered or unexported fields
}

Process is a running program with piped standard streams. A program that needs a terminal instead of pipes is not built: it would be a second start function here returning the same Process over the PTY that internal/node/terminal owns, with Pool unchanged.

func Start

func Start(spec Spec) (*Process, error)

Start writes the declared files, then runs the program in its directory with a scrubbed environment, as the leader of its own process group. Its standard error goes to the Node's log line by line.

func (*Process) Diagnostic

func (process *Process) Diagnostic() string

Diagnostic is the last line the program wrote to standard error.

func (*Process) Done

func (process *Process) Done() <-chan struct{}

Done closes when the program has exited and its group is gone.

func (*Process) Kill

func (process *Process) Kill()

Kill ends the program's whole process group and waits for it.

type Spec

type Spec struct {
	Command string
	Args    []string
	Env     map[string]string
	Files   []File
	Dir     string
	// Host is the Node's environment as NAME=value entries.
	Host []string
	// Log names the program in the Node's diagnostics.
	Log string
}

Spec is one start of a declared program. Dir is the program's own directory: its working directory and the only place Files are written.

Jump to

Keyboard shortcuts

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