#child-process #env-var #unix-socket #environment #subprocess #env

subprocess-inject-env

A crate for dynamically injecting environment variables into child processes

1 unstable release

0.1.0 Sep 5, 2024

#3 in #env-variables

44 downloads per month

Apache-2.0

16KB
331 lines

subprocess-inject-env

This crate provides a mechanism to tweak environment variables within a child subprocess dynamically without the subprocess needing to know anything about it. To do this, we build a .so file that registers a startup hook and launches a background thread listening on a control unix socket. The parent process can then dial in to the control socket, authenticate, and then place an RPC call to setenv. Since the syscall is invoked in the victim child process, the child's environment changes on the fly.

This crate was developed in service of the shpool tool, but it is a general tool so it is split out into its own crate.

subprocess-inject-env is known to work on linux.

Dependencies

~3–12MB
~153K SLoC