]> git.ipfire.org Git - thirdparty/systemd.git/commit
unit-name: introduce "strict" mode for unit name mangling 42638/head
authorFrantisek Sumsal <frantisek@sumsal.cz>
Wed, 17 Jun 2026 12:09:43 +0000 (14:09 +0200)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Thu, 25 Jun 2026 10:58:06 +0000 (12:58 +0200)
commit14b1a92eb251f275d79245e4ed4668fb717804f5
treecf80953a08bd365cec29a2d0cb0a2c367dfc57ff
parent89f1f76624b9d2b18dc332718a33d745e5c0ebdc
unit-name: introduce "strict" mode for unit name mangling

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: #39996
src/basic/unit-name.c
src/basic/unit-name.h
src/run/run.c
src/test/test-unit-name.c