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

Environment variables logic is error prone (for windows particularly) #38

Closed
DaemonSnake opened this issue Jun 28, 2020 · 2 comments
Closed

Comments

@DaemonSnake
Copy link

Hi,
The presence of the following comment environment.hpp

Note that passing an empty container to this method will start the child
process with no environment. To have the child process inherit the environment
of the parent process, call the default constructor instead.

Highlights by its presence that it is not expected behavior.
It is furthermore dangerous to have an empty env as we will highlight it later.

If a user need add an env variable, seeing that there is a environment object and that the environment is immutable (no push),
he will try to use this constructor.

This is without consequence for users of Linux or small applications.
But for Windows this mean that your application won't have any of its system Env variables that are read by windows libraries.
This means that a user trying to just add an env variable might suddenly, and just for windows, have networking issues.
for instance: A non-recoverable error occurred during a database lookup. (os error 11003)

I just was in such a situation and it took a few hours to 3 devs to find it out.

Furthermore the library doesn't offer any way to extend the env which is a pretty basic need, a much more basic one than starting a process with no env.

Therefor creating a limited env should only be a conscious choice on the part of the user and the default behavior should be extension.

@DaanDeMeyer
Copy link
Owner

DaanDeMeyer commented Jun 29, 2020

Hi,

Thanks for creating the issue! In hindsight, it's indeed a lot more intuitive to extend the parent environment with extra environment variables instead of replacing it. The latest commit on master modifies the environment option a bit (which is now named env). It now takes a behavior argument which allows the user to indicate whether he wants to extend the parent environment or start from scratch with an empty environment. By default, the parent environment is extended. Extra environment variables are added via env.extra.

Usage:

reproc::options options;
options.env.behavior = reproc::env::extend;
options.env.extra = std::unordered_map<std::string, std::string> { { "MESSAGE", "EXTEND"} };

Does this fix the issue for you? Any feedback would be welcome and appreciated.

@DaemonSnake
Copy link
Author

Hi,
Thanks very much for the quick respond and change. That's some reactivity right here ^^
I like the new interface it's clean 👍 !
I close the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants