process

package
v3.87.1 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: MIT Imports: 21 Imported by: 5

Documentation

Overview

Package process provides a helper for running and managing a subprocess.

It is intended for internal use by buildkite-agent only.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotWaitStatus = errors.New(
	"unimplemented for systems where exec.ExitError.Sys() is not syscall.WaitStatus",
)

Functions

func Cat

func Cat(path string) (string, error)

Replicates how the command line tool `cat` works, but is more verbose about what it does

func FormatCommand

func FormatCommand(command string, args []string) string

FormatCommand formats a command amd arguments for human reading

func GetPgid

func GetPgid(pid int) (int, error)

func Run

func Run(l logger.Logger, command string, arg ...string) (string, error)

func SignalString added in v3.21.0

func SignalString(s syscall.Signal) string

SignalString returns the name of the given signal. For example, SignalString(syscall.Signal(15)) // "SIGTERM"

func StartPTY

func StartPTY(c *exec.Cmd) (*os.File, error)

Types

type Buffer

type Buffer struct {
	// contains filtered or unexported fields
}

Buffer implements a concurrent-safe output buffer for processes.

func (*Buffer) Close added in v3.51.0

func (l *Buffer) Close() error

Close closes the buffer. Further writes will return io.ErrClosedPipe.

func (*Buffer) ReadAndTruncate added in v3.45.0

func (l *Buffer) ReadAndTruncate() []byte

ReadAndTruncate reads the unread contents of the buffer, and then truncates (empties) the buffer.

func (*Buffer) Write

func (l *Buffer) Write(b []byte) (int, error)

Write appends data to the buffer. If the buffer is closed, it returns io.ErrClosedPipe.

type Config

type Config struct {
	PTY               bool
	Timestamp         bool
	Path              string
	Args              []string
	Env               []string
	Stdin             io.Reader
	Stdout            io.Writer
	Stderr            io.Writer
	Dir               string
	InterruptSignal   Signal
	SignalGracePeriod time.Duration
}

Configuration for a Process

type Process

type Process struct {
	// contains filtered or unexported fields
}

Process is an operating system level process

func New

func New(l logger.Logger, c Config) *Process

New returns a new instance of Process

func (*Process) Done

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

Done returns a channel that is closed when the process finishes

func (*Process) Interrupt

func (p *Process) Interrupt() error

Interrupt the process on platforms that support it, terminate otherwise

func (*Process) Pid

func (p *Process) Pid() int

Pid is the pid of the running process

func (*Process) Run

func (p *Process) Run(ctx context.Context) error

Run the command and block until it finishes

func (*Process) Started

func (p *Process) Started() <-chan struct{}

Started returns a channel that is closed when the process is started

func (*Process) Terminate

func (p *Process) Terminate() error

Terminate the process

func (*Process) WaitResult

func (p *Process) WaitResult() error

WaitResult returns the raw error returned by Wait()

func (*Process) WaitStatus

func (p *Process) WaitStatus() WaitStatus

WaitStatus returns the status of the Wait() call

type Scanner

type Scanner struct {
	// contains filtered or unexported fields
}

func NewScanner

func NewScanner(l logger.Logger) *Scanner

func (*Scanner) ScanLines

func (s *Scanner) ScanLines(r io.Reader, f func(line string)) error

type Signal

type Signal int
const (
	SIGHUP  Signal = 1
	SIGINT  Signal = 2
	SIGQUIT Signal = 3
	SIGUSR1 Signal = 10
	SIGUSR2 Signal = 12
	SIGTERM Signal = 15
)

func ParseSignal

func ParseSignal(sig string) (Signal, error)

func (Signal) String

func (s Signal) String() string

type Timestamper added in v3.60.0

type Timestamper struct {
	// contains filtered or unexported fields
}

Timestamper inserts timestamps generated by a callback at the start of each line, and inside lines when the line is...printed...very...slowly.

func NewTimestamper added in v3.60.0

func NewTimestamper(w io.Writer, f func(t time.Time) string, timeout time.Duration) *Timestamper

NewTimestamper sets up a Timestamper outputting to an io.Writer w. Timestamps are formatted with f, and non-prefix timestamps are inserted on writes that occur after timeout (duration since the previous timestamp).

func (*Timestamper) Write added in v3.60.0

func (p *Timestamper) Write(data []byte) (n int, err error)

Write writes the given data, plus any additional timestamps necessary, to the Timestamper's output. Timestamps are written at the start of each line, and possibly again within lines that are written incrementally over a long period of time.

type WaitStatus added in v3.44.0

type WaitStatus interface {
	ExitStatus() int
	Signaled() bool
	Signal() syscall.Signal
}

Jump to

Keyboard shortcuts

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