Documentation
¶
Overview ¶
Package proc runs external commands with a mandatory deadline.
allbctl inspects the host by shelling out to dozens of tools (package managers, cloud CLIs, ssh-add, gpg, ...). Any one of them can block forever: waiting on a locked agent socket, a credential prompt, or a dead network. Every external command therefore goes through this package, which guarantees that a command is killed once its deadline passes and that it can never read from the terminal.
Index ¶
- Constants
- Variables
- func CombinedOutput(ctx context.Context, name string, args ...string) ([]byte, error)
- func Environ(env []string) []string
- func Exists(name string) bool
- func Observe(fn func(Invocation)) (restore func())
- func Output(ctx context.Context, name string, args ...string) ([]byte, error)
- func OutputEnv(ctx context.Context, env []string, name string, args ...string) ([]byte, error)
- func OutputString(ctx context.Context, name string, args ...string) (string, error)
- func Run(ctx context.Context, name string, args ...string) error
- type Invocation
Constants ¶
const DefaultTimeout = 10 * time.Second
DefaultTimeout bounds a command when the caller's context has no deadline.
Variables ¶
var ErrTimeout = errors.New("command timed out")
ErrTimeout is returned (wrapped) when a command is killed for exceeding its deadline.
Functions ¶
func CombinedOutput ¶
CombinedOutput runs the command and returns standard output and standard error interleaved. Standard input is empty.
func Environ ¶
Environ returns env without the variables that bind git to a specific repository.
When allbctl (or its test suite) is started from a git hook it inherits GIT_DIR and friends. Left in place, every `git -C <other repo> ...` it runs would silently operate on the hook's repository instead: status would report the wrong repository, and `git init` would rewrite the hook repository's own config.
func Observe ¶ added in v0.2.1
func Observe(fn func(Invocation)) (restore func())
Observe registers fn to be told about every command started through this package, after it finished, and returns a function that restores the previous observer. fn is called from whichever goroutine ran the command, so it must be safe for concurrent use. It exists so that the number of child processes a command spawns can be measured and kept in check.
func Output ¶
Output runs the command and returns its standard output. Standard error is discarded and standard input is empty.
func OutputEnv ¶ added in v0.2.0
OutputEnv is Output with extra "KEY=value" variables added to the command's environment, overriding inherited ones of the same name.
func OutputString ¶
OutputString runs the command and returns its standard output with surrounding whitespace removed.
Types ¶
type Invocation ¶ added in v0.2.1
type Invocation struct {
// Argv is the command line: the program as it was named by the caller,
// followed by its arguments.
Argv []string
// Duration is how long the command ran.
Duration time.Duration
}
Invocation describes one external command that was run.