executil

package
v0.18.1 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package executil provides helpers for spawning subprocesses.

Index

Constants

View Source
const DefaultBdTimeout = 5 * time.Minute

DefaultBdTimeout is the default timeout for bd subprocess invocations. bd operations on anvils with remote Dolt (e.g. via kubectl port-forward) and GitHub auto-sync can routinely take 20-30 seconds per write, so the timeout must be generous enough to accommodate that latency.

Variables

This section is empty.

Functions

func DecodeJSON added in v0.13.0

func DecodeJSON(data []byte, v any) error

DecodeJSON decodes one JSON value from subprocess output that may contain leading or trailing non-JSON noise (log lines, diagnostics, etc.).

It first tries to decode the whole output. On failure it walks top-level '{' positions (then top-level '[' positions) using bytes.IndexByte in a streaming loop, returning the first candidate that succeeds. Only positions at start-of-input or preceded by whitespace are considered, so nested objects inside arrays are not treated as standalone top-level values. The scan is bounded to maxJSONScanBytes bytes and maxJSONCandidates attempts.

func HideWindow

func HideWindow(cmd *exec.Cmd) *exec.Cmd

HideWindow configures cmd to not create a visible console window. On Windows this sets CREATE_NO_WINDOW. On other platforms it is a no-op.

func KillProcessTree added in v0.16.0

func KillProcessTree(cmd *exec.Cmd) error

KillProcessTree forcibly terminates cmd's root process and every descendant. It is best-effort: callers should not rely on complete cleanup in all scenarios, but it covers the common cases that cause worktree lock issues.

On Unix it requires cmd to have been started with SetProcessGroup so the descendants share a process group that can be signalled via kill(-pgid, sig). In that configuration it is safe to call after cmd has already exited, and it can still reap background children that remained in the process group (for example `npx http-server` started in the background by a build script).

On Windows it shells out to `taskkill /T /F /PID <pid>`, which is effective while the root PID still exists. If the root process has already fully exited, Windows does not reliably support targeting the former process tree by that PID alone, so reaping leftover descendants is best-effort and not guaranteed.

Returns nil when there is nothing to kill (cmd or cmd.Process is nil). Errors from the underlying signal/taskkill invocation are returned so callers can log them, but it is generally safe to ignore the error in teardown paths.

func SetProcessGroup added in v0.13.0

func SetProcessGroup(cmd *exec.Cmd) *exec.Cmd

SetProcessGroup configures cmd to start in its own process group. On Unix this sets Setpgid so signals can be sent to the entire group via kill(-pid, sig). On Windows this sets CREATE_NEW_PROCESS_GROUP.

Types

This section is empty.

Jump to

Keyboard shortcuts

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