summaryrefslogtreecommitdiffstats
path: root/src/sleep/sleep.c
diff options
context:
space:
mode:
authorMike Yuan <me@yhndnzj.com>2024-06-11 16:00:22 +0200
committerMike Yuan <me@yhndnzj.com>2024-07-17 18:14:33 +0200
commitb1ed7e6749541f03c2a35f05a91c5d950908e71f (patch)
tree70b206117bc39fca8c72d833ec0f960d8ac272db /src/sleep/sleep.c
parentsleep: also log about errno when getenv_bool fails (diff)
downloadsystemd-b1ed7e6749541f03c2a35f05a91c5d950908e71f.tar.xz
systemd-b1ed7e6749541f03c2a35f05a91c5d950908e71f.zip
sleep,home: always initialize UnitFreezer if used
Previously, unit_freezer_new_freeze() would only return UnitFreezer object if FreezeUnit() succeeds. This is not ideal though, as a failed bus call doesn't mean the action actually failed. E.g. a timeout might occur because pid1 is waiting for cgroup event from kernel, while the bus call timeout was exceeded (#33269). In such a case, ThawUnit() will never be called, resulting in frozen units remain that way after resuming from sleep. Therefore, let's get rid of unit_freezer_new_freeze(), and make sure as long as unit freezer is involved, we'll call ThawUnit() when we're done. This should make things a lot more robust.
Diffstat (limited to '')
-rw-r--r--src/sleep/sleep.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c
index 7e5075a63c..15ef7ae913 100644
--- a/src/sleep/sleep.c
+++ b/src/sleep/sleep.c
@@ -604,9 +604,13 @@ static int run(int argc, char *argv[]) {
r = getenv_bool("SYSTEMD_SLEEP_FREEZE_USER_SESSIONS");
if (r < 0 && r != -ENXIO)
log_warning_errno(r, "Cannot parse value of $SYSTEMD_SLEEP_FREEZE_USER_SESSIONS, ignoring: %m");
- if (r != 0)
- (void) unit_freezer_new_freeze(SPECIAL_USER_SLICE, &user_slice_freezer);
- else
+ if (r != 0) {
+ r = unit_freezer_new(SPECIAL_USER_SLICE, &user_slice_freezer);
+ if (r < 0)
+ return r;
+
+ (void) unit_freezer_freeze(user_slice_freezer);
+ } else
log_notice("User sessions remain unfrozen on explicit request ($SYSTEMD_SLEEP_FREEZE_USER_SESSIONS=0).\n"
"This is not recommended, and might result in unexpected behavior, particularly\n"
"in suspend-then-hibernate operations or setups with encrypted home directories.");