From: Luca Boccassi Date: Fri, 5 Apr 2024 23:00:41 +0000 (+0100) Subject: run: query for SoftRebootsCount only for system scope runs X-Git-Tag: v256-rc1~287 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9dd174dc232af12ba5898d8ede9aca370ef9a85f;p=thirdparty%2Fsystemd.git run: query for SoftRebootsCount only for system scope runs 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 --- diff --git a/src/run/run.c b/src/run/run.c index 9349bfafbc4..9d84d063316 100644 --- a/src/run/run.c +++ b/src/run/run.c @@ -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)