]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
run: query for SoftRebootsCount only for system scope runs
authorLuca Boccassi <bluca@debian.org>
Fri, 5 Apr 2024 23:00:41 +0000 (00:00 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Sun, 7 Apr 2024 09:20:04 +0000 (10:20 +0100)
Only the system manager records soft reboots, and the user session is
restarted anyway so it doesn't suffer from the ID clash issue

Follow-up for ed358516937780b524a2cfa833427da3df1bc87f

src/run/run.c

index 9349bfafbc4bb5d5968377c49bbc028a4d4627bd..9d84d063316ee324421853cb7b36fab3c2fbf26b 100644 (file)
@@ -1321,6 +1321,7 @@ static int make_unit_name(sd_bus *bus, UnitType t, char **ret) {
         assert(bus);
         assert(t >= 0);
         assert(t < _UNIT_TYPE_MAX);
+        assert(ret);
 
         r = sd_bus_get_unique_name(bus, &unique);
         if (r < 0) {
@@ -1355,11 +1356,15 @@ static int make_unit_name(sd_bus *bus, UnitType t, char **ret) {
         /* The unique D-Bus names are actually unique per D-Bus instance, so on soft-reboot they will wrap
          * and start over since the D-Bus broker is restarted. If there's a failed unit left behind that
          * hasn't been garbage collected, we'll conflict. Append the soft-reboot counter to avoid clashing. */
-        _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
-        r = bus_get_property_trivial(
-                        bus, bus_systemd_mgr, "SoftRebootsCount", &error, 'u', &soft_reboots_count);
-        if (r < 0)
-                log_debug_errno(r, "Failed to get SoftRebootsCount property, ignoring: %s", bus_error_message(&error, r));
+        if (arg_runtime_scope == RUNTIME_SCOPE_SYSTEM) {
+                _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
+                r = bus_get_property_trivial(
+                                bus, bus_systemd_mgr, "SoftRebootsCount", &error, 'u', &soft_reboots_count);
+                if (r < 0)
+                        log_debug_errno(r,
+                                        "Failed to get SoftRebootsCount property, ignoring: %s",
+                                        bus_error_message(&error, r));
+        }
 
         if (soft_reboots_count > 0) {
                 if (asprintf(&p, "run-u%s-s%u.%s", id, soft_reboots_count, unit_type_to_string(t)) < 0)