]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
run: tweak algorithm for generating unit name from dbus unique name
authorLennart Poettering <lennart@poettering.net>
Thu, 4 Mar 2021 15:23:46 +0000 (16:23 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Thu, 4 Mar 2021 20:50:41 +0000 (20:50 +0000)
This reverts behaviour of systemd-run's unit name generation to the
status quo ante of #18871: we chop off the ":1." prefix if we can.
However, to address the issue that the unique name can overrun we then
do what #18871 did as fallback: only chop off the ":" prefix.

This way we should have pretty names that look like they always looked
in the common case, but in the case of a unique name overrun we still
will have names that work.

Follow-up for #18871

src/run/run.c

index 8c036857cf21747a3dd7deec0509ddcffe889386..ac405d39d742d32e0f0515b6217d633f3ae21ece 100644 (file)
@@ -956,10 +956,12 @@ static int make_unit_name(sd_bus *bus, UnitType t, char **ret) {
                 return 0;
         }
 
-        /* We managed to get the unique name, then let's use that to
-         * name our transient units. */
+        /* We managed to get the unique name, then let's use that to name our transient units. */
 
-        id = startswith(unique, ":");
+        id = startswith(unique, ":1."); /* let' strip the usual prefix */
+        if (!id)
+                id = startswith(unique, ":"); /* the spec only requires things to start with a colon, hence
+                                               * let's add a generic fallback for that. */
         if (!id)
                 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
                                        "Unique name %s has unexpected format.",