runner

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package runner runs the programs that ncly and its extensions start, as the Programs that ncly runs section of contract.md defines: their environment, their process group, their cancellation, and their exit code.

Index

Constants

View Source
const DrainLimit = 2 * time.Second

DrainLimit bounds how long the runner reads a program's streams after the program exits, because a descendant may hold them open. It runs on its own clock, apart from Cleanup.

Variables

View Source
var Cleanup = 15 * time.Second

Cleanup bounds the time that a program and its descendants get to stop after a signal, before SIGKILL ends what still runs. Only the test binary shortens it.

Functions

func Environ

func Environ(parent []string, set map[string]string) []string

Environ returns the environment of a program: its parent's, without the key of any service, which needs a grant, and with each variable of set given its value, or removed when that value is empty.

func OnSignal

func OnSignal() context.Context

OnSignal returns a context that the first Ctrl-C or SIGTERM ends, with that signal as its cause. The handler stays registered for the life of the process, so a later signal never ends it.

func SignalOf

func SignalOf(ctx context.Context) os.Signal

SignalOf returns the signal that ended ctx, and SIGTERM when ctx ended for another reason, such as a timeout.

Types

type Program

type Program struct {
	Path string
	// Name, when set, is the program's argv[0] instead of Path, as ncly
	// starts itself under the name of a bundled extension.
	Name string
	Args []string
	Env  []string
	// Stdin, Stdout, and Stderr reach the program. An *os.File passes as it
	// is, so the program sees the terminal when it is one.
	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer
	// Terminal keeps the program in the process group of ncly, because it
	// may read the terminal, as an extension does. Any other program starts
	// in its own process group.
	Terminal bool
}

Program is one program to run.

type Result

type Result struct {
	// Exit is the program's exit code, or 128 plus the number of the signal
	// that ended it, as a shell reports it. It is -1 when ctx had ended
	// before the program started, so it never ran.
	Exit int
	// Signal is the signal that ended ctx before the program exited, or nil
	// when the program exited first.
	Signal os.Signal
}

Result is how a program ended.

func Run

func Run(ctx context.Context, p Program) (Result, error)

Run starts the program and waits for it to exit. When ctx ends first, Run sends the signal that ended it, or SIGTERM for any other end, to every descendant of ncly that it can reach, the program included, and sends SIGKILL to what still runs once Cleanup has passed. A later end of ctx changes nothing. Run reads a stream that is not a file for at most DrainLimit after the program exits.

type SignalCause

type SignalCause struct{ Signal os.Signal }

SignalCause is the cause of a context that a signal ended.

func (SignalCause) Error

func (c SignalCause) Error() string

Jump to

Keyboard shortcuts

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