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

fix: do not erase systemd environment variables #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lbarthon
Copy link

In some scenarios, one might need to call ListenFd::from_env many times. Due to those two problematic lines, this is impossible, as the first time will erase the environment, and all the others will be ListenFd::empty.

In case where one wants to call this from a library, or any such thing, it makes the library completely unusable. There is also no reason for it to mutate the environment like that. Keeping those variables has effectively no impact.

In some scenarios, one might need to call ListenFd::from_env many times. Due to
those two problematic lines, this is impossible, as the first time will erase
the environment, and all the others will be ListenFd::empty.

In case where one wants to call this from a library, or any such thing, it
makes the library completely unusable. There is also no reason for it to mutate
the environment like that. Keeping those variables has effectively no impact.
@lbarthon lbarthon closed this Jan 31, 2024
@lbarthon lbarthon reopened this Jan 31, 2024
@mitsuhiko
Copy link
Owner

How do other systems do this? This seems risky to me. Then the user would have to manually remove them.

@curvature
Copy link

How do other systems do this? This seems risky to me. Then the user would have to manually remove them.

Systemd managed services can reload themselves by executing a child process of its very own executable(argv[0]), in which case the child process needs to inherit the systemd sockets just as its parent did. To me it's clearing the env vars, not keeping them that begs the question of justification.

@mitsuhiko
Copy link
Owner

I suppose the solution is to provide another API that does not unset it. I'm honestly not sure what the recommended path is. Originally when I used systemd it unset those variables under normal circumstances from my memory, but I can see that the sd_listen_fds function gives the user an option.

@septatrix
Copy link

How do other systems do this? This seems risky to me. Then the user would have to manually remove them.

Systemd managed services can reload themselves by executing a child process of its very own executable(argv[0]), in which case the child process needs to inherit the systemd sockets just as its parent did.

Services replacing themselves is strongly discouraged by systemd as they do not get a clean state environment

@septatrix
Copy link

I suppose the solution is to provide another API that does not unset it

Systemd offers a flag for this:

int sd_listen_fds(int unset_environment);
int sd_listen_fds_with_names(int unset_environment, char*** names);

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

Successfully merging this pull request may close these issues.

4 participants