process

package
v3.46.1 Latest Latest
Warning

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

Go to latest
Published: May 8, 2023 License: MIT Imports: 19 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

This section is empty.

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) 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.

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
}

Configuration for a Process

type Prefixer

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

Prefixer inserts prefixes generated by a callback before each line. To ensure any temporarily-buffered data is written out, be sure to call Flush when done.

func NewPrefixer

func NewPrefixer(w io.Writer, f func() string) *Prefixer

NewPrefixer sets up a Prefixer outputting to an io.Writer w and reading prefixes from the callback f.

func (*Prefixer) Write

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

Write writes the given data, plus any additional prefixes necessary, to the Prefixer's output. Prefixes are computed at the *start* of each line.

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 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