From 5ba6321d863a653c2d2e6cf7641cfc7f378e35a2 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Thu, 7 Mar 2024 02:20:26 +0800 Subject: [PATCH 1/3] bus-unit-util: define FREEZE_BUS_CALL_TIMEOUT locally Follow-up for f274f8bf256702c5fd0c68d3f7bd6aeba74dfcf0 We define *_SLOW_BUS_CALL_TIMEOUT in each component's own file too. This one is no different and doesn't need to be in constants.h IMO. --- src/basic/constants.h | 3 --- src/shared/bus-unit-util.c | 6 ++++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/basic/constants.h b/src/basic/constants.h index 6bb5f3c281..ef3af88a9d 100644 --- a/src/basic/constants.h +++ b/src/basic/constants.h @@ -42,9 +42,6 @@ #define DEFAULT_START_LIMIT_INTERVAL (10*USEC_PER_SEC) #define DEFAULT_START_LIMIT_BURST 5 -/* Wait for 1.5 seconds at maximum for freeze operation */ -#define FREEZE_TIMEOUT (1500 * USEC_PER_MSEC) - /* The default time after which exit-on-idle services exit. This * should be kept lower than the watchdog timeout, because otherwise * the watchdog pings will keep the loop busy. */ diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c index 2f485f810d..536acc874a 100644 --- a/src/shared/bus-unit-util.c +++ b/src/shared/bus-unit-util.c @@ -10,7 +10,6 @@ #include "cgroup-setup.h" #include "cgroup-util.h" #include "condition.h" -#include "constants.h" #include "coredump-util.h" #include "cpu-set-util.h" #include "dissect-image.h" @@ -2939,6 +2938,9 @@ int bus_service_manager_reload(sd_bus *bus) { return 0; } +/* Wait for 1.5 seconds at maximum for freeze operation */ +#define FREEZE_BUS_CALL_TIMEOUT (1500 * USEC_PER_MSEC) + int unit_freezer_new(const char *name, UnitFreezer *ret) { _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL; _cleanup_free_ char *namedup = NULL; @@ -2955,7 +2957,7 @@ int unit_freezer_new(const char *name, UnitFreezer *ret) { if (r < 0) return log_debug_errno(r, "Failed to open connection to systemd: %m"); - (void) sd_bus_set_method_call_timeout(bus, FREEZE_TIMEOUT); + (void) sd_bus_set_method_call_timeout(bus, FREEZE_BUS_CALL_TIMEOUT); *ret = (UnitFreezer) { .name = TAKE_PTR(namedup), From dc35af47df5dd0b86be0943291c2deb6dbb4add5 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Thu, 7 Mar 2024 02:23:39 +0800 Subject: [PATCH 2/3] bus-unit-util: trivial follow-up for UnitFreezer Follow-up for 7483708131b474d92c9207c8c6340b450b58cb94 Make sure that function param names match between source and header. Also, place UnitFreezer params in front. --- src/shared/bus-unit-util.c | 54 ++++++++++++++++++++------------------ src/shared/bus-unit-util.h | 10 +++---- 2 files changed, 33 insertions(+), 31 deletions(-) diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c index 536acc874a..0fedafd881 100644 --- a/src/shared/bus-unit-util.c +++ b/src/shared/bus-unit-util.c @@ -2966,31 +2966,6 @@ int unit_freezer_new(const char *name, UnitFreezer *ret) { return 0; } -static int unit_freezer_action(bool freeze, UnitFreezer *f) { - _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; - int r; - - assert(f); - assert(f->bus); - assert(f->name); - - r = bus_call_method(f->bus, bus_systemd_mgr, freeze ? "FreezeUnit" : "ThawUnit", - &error, NULL, "s", f->name); - if (r < 0) - return log_debug_errno(r, "Failed to %s unit %s: %s", freeze ? "freeze" : "thaw", - f->name, bus_error_message(&error, r)); - - return 0; -} - -int unit_freezer_freeze(UnitFreezer *f) { - return unit_freezer_action(true, f); -} - -int unit_freezer_thaw(UnitFreezer *f) { - return unit_freezer_action(false, f); -} - void unit_freezer_done(UnitFreezer *f) { assert(f); @@ -2998,6 +2973,35 @@ void unit_freezer_done(UnitFreezer *f) { f->bus = sd_bus_flush_close_unref(f->bus); } +static int unit_freezer_action(UnitFreezer *f, bool freeze) { + _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; + int r; + + assert(f); + assert(f->name); + assert(f->bus); + + r = bus_call_method(f->bus, bus_systemd_mgr, + freeze ? "FreezeUnit" : "ThawUnit", + &error, + /* reply = */ NULL, + "s", + f->name); + if (r < 0) + return log_debug_errno(r, "Failed to %s unit %s: %s", + freeze ? "freeze" : "thaw", f->name, bus_error_message(&error, r)); + + return 0; +} + +int unit_freezer_freeze(UnitFreezer *f) { + return unit_freezer_action(f, true); +} + +int unit_freezer_thaw(UnitFreezer *f) { + return unit_freezer_action(f, false); +} + int unit_freezer_new_freeze(const char *name, UnitFreezer *ret) { _cleanup_(unit_freezer_done) UnitFreezer f = {}; int r; diff --git a/src/shared/bus-unit-util.h b/src/shared/bus-unit-util.h index 3c6a001069..a1518158ff 100644 --- a/src/shared/bus-unit-util.h +++ b/src/shared/bus-unit-util.h @@ -42,13 +42,11 @@ typedef struct UnitFreezer { } UnitFreezer; int unit_freezer_new(const char *name, UnitFreezer *ret); +void unit_freezer_done(UnitFreezer *f); -int unit_freezer_freeze(UnitFreezer *freezer); - -int unit_freezer_thaw(UnitFreezer *freezer); - -void unit_freezer_done(UnitFreezer *freezer); +int unit_freezer_freeze(UnitFreezer *f); +int unit_freezer_thaw(UnitFreezer *f); int unit_freezer_new_freeze(const char *name, UnitFreezer *ret); -void unit_freezer_done_thaw(UnitFreezer *freezer); +void unit_freezer_done_thaw(UnitFreezer *f); From 45df233e5f8ad93eace3982089bb8883e524339c Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Thu, 7 Mar 2024 02:53:43 +0800 Subject: [PATCH 3/3] sleep: fix typo (sysupend -> suspend) --- src/sleep/sleep.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c index 16ad48b386..0f619ce0f5 100644 --- a/src/sleep/sleep.c +++ b/src/sleep/sleep.c @@ -606,7 +606,7 @@ static int run(int argc, char *argv[]) { } else log_notice("User sessions remain unfrozen on explicit request " "($SYSTEMD_SLEEP_FREEZE_USER_SESSIONS is set to false). This is not recommended, " - "and might result in unexpected behavior, particularly in sysupend-then-hibernate " + "and might result in unexpected behavior, particularly in suspend-then-hibernate " "operations or setups with encrypted home directories."); switch (arg_operation) {