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 EnvironmentFile instead of Environment in systemd units. Closes #… #23337

Closed
wants to merge 1 commit into from

Conversation

teh
Copy link
Contributor

@teh teh commented Mar 1, 2017

…22829.

This is the simplest solution I could come up with.

We could also add an if-statement and only write environment files if the line would be longer than 2048, but then we'd introduce a potentially untested branch.

@mention-bot
Copy link

@teh, thanks for your PR! By analyzing the history of the files in this pull request, we identified @edolstra, @bluescreen303 and @abbradar to be potential reviewers.

@edolstra
Copy link
Member

edolstra commented Mar 1, 2017

Maybe this can be made conditional on the length of the string? Otherwise it's going to add a huge number of files to the system closure.

@teh
Copy link
Contributor Author

teh commented Mar 1, 2017

@edolstra - yea see my comment on merge. My main worry was having a less-tested path around. Looking at my servers this will add ~200 files + symlinks. If you still prefer the conditional I'll add that.

@edolstra
Copy link
Member

edolstra commented Mar 1, 2017

Yeah, I'd prefer to avoid the overhead for the common case.

@teh
Copy link
Contributor Author

teh commented Mar 1, 2017

@edolstra - Please have a look. I think we also had a bug in that the entire line musn't be longer than 2048, and AFAICT we only checked the right hand side of Environment=.

Now that I think about it I'm not even sure the assumption holds that EnvironmentFile is allowed to have longer lines. I'll have a look at the systemd code.

@teh
Copy link
Contributor Author

teh commented Mar 1, 2017

https://github.com/systemd/systemd/blob/b965427b59a6912a46e1cdb26b732d3ea396b332/src/basic/fileio.c#L302 - doesn't look like there's a limit so the spillover solution should work.

Off-topic: The systemd parsing code looks quite scary, I really wish it wasn't c ...

@samueldr
Copy link
Member

samueldr commented Aug 24, 2018

Making rounds in the older PRs, this seems a worthwhile addition, what's left to do, if anything, before reviewing and then merging?

I ran the added test:

~/.../nixos/tests $ nix-build systemd-spill-to-environmentfile.nix

And everything ran fine, while running the same test on nixpkgs-unstable (without the fix from this patch) fails as expected

~/.../nixos/tests $ nix-build systemd-spill-to-environmentfile.nix
error: The value of the environment variable ‘LONGVAR’ in systemd service ‘long-env-unit.service’ is too long.
(use '--show-trace' to show detailed location information)

@aanderse
Copy link
Member

@teh this is super useful... are you happy with this being merged as is? I don't notice any obvious problems so after a rebase and whatnot LGTM 👍

@teh
Copy link
Contributor Author

teh commented May 23, 2019

@aanderse it seem the max line length is now ~1MiB but when I tried it failed so I did a rebase with 2048.

@aanderse
Copy link
Member

If the max length has been increased and it doesn't seem to be working we should probably investigate that. I would say this PR is no longer required but instead an investigation into why you are having issues and see if we can reproduce? What is your test case?

@teh
Copy link
Contributor Author

teh commented May 24, 2019

I replaced the spillover check with 1048576 + and repeated the 8-char longvar 131072 times. That caused systemd to complain.

I agree that with 1MB line length this is much less acute. My getconf ARG_MAX is 2MiB so it's still a problem but more theoretical at this point. Happy to close.

@aanderse
Copy link
Member

Thanks @teh!

@aanderse aanderse closed this May 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants