unit-name: introduce "strict" mode for unit name mangling#42638
Merged
Conversation
Claude review of PR #42638 (14b1a92)The PR is sound — the new All prior items have been addressed or dismissed by the author. This run surfaced two minor new style nits (appended below). Suggestions
Nits
|
58c4ba5 to
674fd18
Compare
fc47b26 to
bbb9218
Compare
unit_name_mangle_with_suffix() is quite benevolent by default and allows the unit to "transition" into a different unit type than what's requested via its suffix argument. For example, calling unit_name_mangle_with_suffix() with "/foo/bar" as a unit name and ".service" as a suffix would give you "foo-bar.mount", without any warning or error. This could then lead to a quite confusing errors in certain situations: ~# systemd-run --remain-after-exit --unit /foo/bar true Failed to start transient service unit: Cannot set property RemainAfterExit, or unknown property. Given we can't change the default behaviour of unit_name_mangle_with_suffix() as some parts of systemd already depend on its "benevolence" (like systemctl), let's introduce a new flag - UNIT_NAME_MANGLE_STRICT - that checks if the mangled/resolved unit name's suffix matches the requested one and errors out if not. With the flag used throughout systemd-run's code, the error in the above case is now a bit more clear: ~# build/systemd-run --remain-after-exit --unit /foo/bar true Path "/foo/bar" resolves to unit type "mount", but "service" is expected as unit. Failed to mangle unit name: Invalid argument Resolves: systemd#39996
bbb9218 to
14b1a92
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
unit_name_mangle_with_suffix() is quite benevolent by default and allows
the unit to "transition" into a different unit type than what's
requested via its suffix argument. For example, calling
unit_name_mangle_with_suffix() with "/foo/bar" as a unit name and
".service" as a suffix would give you "foo-bar.mount", without any
warning or error.
This could then lead to a quite confusing errors in certain situations:
Given we can't change the default behaviour of
unit_name_mangle_with_suffix() as some parts of systemd already depend
on its "benevolence" (like systemctl), let's introduce a new flag -
UNIT_NAME_MANGLE_STRICT - that checks if the mangled/resolved unit
name's suffix matches the requested one and errors out if not.
With the flag used throughout systemd-run's code, the error in the above
case is now a bit more clear:
Resolves: #39996