executil

package
v0.39.0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsTerminatedExitErr added in v0.2.0

func IsTerminatedExitErr(err error) bool

IsTerminatedExitErr returns true if the error is the expected error when the process was terminated via Cmd.TerminateProcessGroup and the process exited within the grace period.

On Unix, multiple errors can happen when a SIGTERM is sent to the process group:

  • The process can have exit code 143, which is the expected exit code when a process receives a SIGTERM
  • The process can have exit code -1 and the signal of the wait status set to SIGTERM
  • In case that the process doesn't handle the SIGTERM fast enough and tries to write to the pipe which was already closed by TerminateProcessGroup, the process has exit code -1 and the signal of the wait status is set to SIGPIPE

Types

type Cmd

type Cmd struct {
	*exec.Cmd

	CloseAfterWait []io.Closer
	// contains filtered or unexported fields
}

Cmd provides the same functionality as exec.Cmd plus some utility methods.

func Command

func Command(name string, arg ...string) *Cmd

func CommandContext

func CommandContext(ctx context.Context, name string, arg ...string) *Cmd

CommandContext is like Command but includes a context.

The provided context is used to terminate the process group (by first sending SIGTERM to the process group and after a grace period of 3 seconds SIGKILL) if the context becomes done before the command completes on its own. In that case, Cmd.TerminatedAfterContextDone() returns true.

func (*Cmd) Run

func (c *Cmd) Run() error

Same as exec.Cmd.Run() but uses the wrapper methods of this struct.

func (*Cmd) Start

func (c *Cmd) Start() error

Does the same as exec.Cmd.Start(), but also closes the write ends of tee pipes (if there are any) on the same errors that exec.Cmd.Start() closes its open pipes.

func (*Cmd) StderrTeePipe

func (c *Cmd) StderrTeePipe(writer io.Writer) (io.ReadCloser, error)

Same as StdoutTeePipe but for stderr.

func (*Cmd) StdoutTeePipe

func (c *Cmd) StdoutTeePipe(writer io.Writer) (io.ReadCloser, error)

StdoutTeePipe is similar to StdoutPipe, but everything written to the pipe is also copied to the specified writer (similar to tee(1)).

In contrast to StdoutPipe, Wait will *not* automatically close the pipe, so it's the caller's responsibility to close the pipe. In effect, it is fine to call Wait before all reads from the pipe have completed.

func (*Cmd) TerminateProcessGroup

func (c *Cmd) TerminateProcessGroup() error

func (*Cmd) TerminatedAfterContextDone

func (c *Cmd) TerminatedAfterContextDone() bool

func (*Cmd) Wait

func (c *Cmd) Wait() error

Does the same as exec.Cmd.Wait() but also closes the write ends of tee pipes (if there are any).

Jump to

Keyboard shortcuts

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