Documentation
¶
Overview ¶
Package safeexec provides filtered-environment subprocess execution with inactivity-based timeouts. It is the single place where os/exec is called from extensions — all shell helpers route through here.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FilterEnv ¶
FilterEnv returns a copy of environ containing only safe variables. If environ is nil, os.Environ() is used.
func Run ¶
func Run(ctx context.Context, dir string, inactivity time.Duration, name string, args ...string) (string, error)
Run is a convenience wrapper: executes name+args in dir, captures stdout, returns stderr on error. Optionally resets an inactivity watchdog on each output chunk.
func SafeCmd ¶
func SafeCmd(ctx context.Context, dir string, inactivity time.Duration, name string, args ...string) (cmd *exec.Cmd, stop func())
SafeCmd wraps exec.Cmd with a filtered environment and optional inactivity timeout. The caller is responsible for cmd.Start() / cmd.Wait().
Usage:
cmd, stop := safeexec.SafeCmd(ctx, dir, inactivity, "sh", "-c", command) defer stop() // wire cmd.Stdout / cmd.Stderr as needed err := cmd.Run()
Types ¶
type InactivityTimer ¶
type InactivityTimer struct {
// contains filtered or unexported fields
}
InactivityTimer cancels a context after the given duration of no Write calls. Useful for killing subprocesses that produce no output and appear stalled.
func NewInactivityTimer ¶
func NewInactivityTimer(cancel context.CancelFunc, dur time.Duration) *InactivityTimer
NewInactivityTimer creates a timer that fires after dur of inactivity. The returned cancel func should be deferred by the caller.
func (*InactivityTimer) Stop ¶
func (t *InactivityTimer) Stop()
Stop cancels the inactivity timer without firing it.