proc

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: Apache-2.0 Imports: 9 Imported by: ? 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 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

View Source
const DefaultTimeout = 10 * time.Second

DefaultTimeout bounds a command when the caller's context has no deadline.

Variables

View Source
var ErrTimeout = errors.New("command timed out")

ErrTimeout is returned (wrapped) when a command is killed for exceeding its deadline.

Functions

func CombinedOutput

func CombinedOutput(ctx context.Context, name string, args ...string) ([]byte, error)

CombinedOutput runs the command and returns standard output and standard error interleaved. Standard input is empty.

func Environ

func Environ(env []string) []string

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 Exists

func Exists(name string) bool

Exists reports whether name resolves to an executable on PATH.

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

func Output(ctx context.Context, name string, args ...string) ([]byte, error)

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

func OutputEnv(ctx context.Context, env []string, name string, args ...string) ([]byte, error)

OutputEnv is Output with extra "KEY=value" variables added to the command's environment, overriding inherited ones of the same name.

func OutputString

func OutputString(ctx context.Context, name string, args ...string) (string, error)

OutputString runs the command and returns its standard output with surrounding whitespace removed.

func Run

func Run(ctx context.Context, name string, args ...string) error

Run runs the command, discarding its output.

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.

Jump to

Keyboard shortcuts

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