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 ¶
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 ¶
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 ¶
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.
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 ¶
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 ¶
SignalCause is the cause of a context that a signal ended.
func (SignalCause) Error ¶
func (c SignalCause) Error() string