Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use env_clear for environment variable reset #71

Open
cd-work opened this issue Mar 12, 2024 · 0 comments
Open

Use env_clear for environment variable reset #71

cd-work opened this issue Mar 12, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@cd-work
Copy link
Collaborator

cd-work commented Mar 12, 2024

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 cd-work added the enhancement New feature or request label Mar 12, 2024
@cd-work cd-work self-assigned this May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant