From: Lennart Poettering Date: Thu, 25 Jun 2026 15:18:55 +0000 (+0200) Subject: unit-name: introduce "strict" mode for unit name mangling (#42638) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4162b65338c5a59cabb8d141e8d1e0ed8d50b0a5;p=thirdparty%2Fsystemd.git unit-name: introduce "strict" mode for unit name mangling (#42638) 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 --- 4162b65338c5a59cabb8d141e8d1e0ed8d50b0a5