From 9dd174dc232af12ba5898d8ede9aca370ef9a85f Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Sat, 6 Apr 2024 00:00:41 +0100 Subject: [PATCH] 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 --- src/run/run.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) 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) -- 2.47.3