birdcage icon indicating copy to clipboard operation
birdcage copied to clipboard

Use `env_clear` for environment variable reset

Open cd-work opened this issue 1 year ago • 0 comments

We're already using the Command interface on all platforms since we need to spawn a separate process on Linux. However we're still manually removing the environment variables from the process which seems fragile.

Instead, we should use the Command::env_clear method instead: https://doc.rust-lang.org/std/process/struct.Command.html#method.env_clear

This removes all inherited environment variables, after which they can be added again with Command::env and Command::envs. The inherited variables stay cleared.

This also works on Linux with the new PID 1 init, even if PID 1 itself still has these variables set, since PID 2 cannot read /proc/1/environ based on my testing.

cd-work avatar Mar 12 '24 21:03 cd-work