Documentation
¶
Overview ¶
Package childproc builds and manages a single child process with portable stdio, signal, credential, and extra-file-descriptor plumbing. It receives exec specs from cmd/mproxy-agent and feeds the agent's mux loop with process handles, pipes, exit codes, and signal delivery.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CloseChildSide ¶
CloseChildSide releases the child-side ends of the std pipes and extra files attached to cmd. Call this once Start has succeeded so the child becomes the only holder of its end of each pipe.
func ExitCode ¶
func ExitCode(state *os.ProcessState) int
ExitCode extracts the exit code from a finished process state. Returns 128+signal when the process was killed by a signal.
Types ¶
type Pipes ¶
type Pipes struct {
Stdin *os.File // parent writes → child stdin
Stdout *os.File // parent reads ← child stdout
Stderr *os.File // parent reads ← child stderr
Extra map[uint32]*os.File // parent end of each extra-fd channel
}
Pipes holds the parent-side ends of the standard pipes and any extra-fd channels connected to the child process. The child-side ends live on the *exec.Cmd until Start, after which CloseChildSide releases them in the parent.
func Build ¶
Build creates an *exec.Cmd from spec with:
- A fresh process group (Setpgid) so signals can be delivered to the whole tree.
- Optional credential drop based on $SUDO_UID/$SUDO_GID.
- Pipes for stdin/stdout/stderr.
- Unix socketpairs for each requested extra fd.
The returned Pipes holds the parent-side ends. The caller must Close them when done.
type Spec ¶
type Spec struct {
Path string
Argv []string
Env []string
Cwd string
ExtraFDs []uint32
// DropSudoCredentials, when true, instructs Build to launch the
// child with reduced privileges if the current process is running
// with elevated ones:
// - On unix, switch the child's uid/gid to the values in
// $SUDO_UID / $SUDO_GID if those variables are set.
// - On Windows, if the current process token is elevated (UAC
// "split token" admin), launch the child with the linked
// filtered (standard-user) token. If the current token is not
// elevated, this is a no-op.
DropSudoCredentials bool
}
Spec describes the command to launch. It is intentionally decoupled from any wire protocol so this package can be reused.