diff options
author | Marc Reisner <reisner.marc@gmail.com> | 2024-08-05 01:01:34 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-05 01:01:34 +0200 |
commit | 2d00f4c306b4a5c3edef44e17c9efcf10cfb5d9b (patch) | |
tree | 3d5d182f451033bccffff19172fe660f097a42ac /src/sleep/sleep.c | |
parent | Merge pull request #33918 from YHNdnzj/exec-cred-cleanup (diff) | |
download | systemd-2d00f4c306b4a5c3edef44e17c9efcf10cfb5d9b.tar.xz systemd-2d00f4c306b4a5c3edef44e17c9efcf10cfb5d9b.zip |
sleep: add HibernateOnACPower= option (#33846)
* Add HibernateOnACPower= systemd-sleep configuration option
Diffstat (limited to 'src/sleep/sleep.c')
-rw-r--r-- | src/sleep/sleep.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c index 15ef7ae913..3f113fff74 100644 --- a/src/sleep/sleep.c +++ b/src/sleep/sleep.c @@ -390,7 +390,15 @@ static int custom_timer_suspend(const SleepConfig *sleep_config) { } } - /* Do not suspend more than HibernateDelaySec= */ + /* Do not suspend more than HibernateDelaySec= unless HibernateOnACPower=no and currently on AC power */ + if (!sleep_config->hibernate_on_ac_power) { + /* Do not allow "decay" to suspend if the system has no battery. */ + if (hashmap_isempty(last_capacity)) + log_once(LOG_WARNING, "HibernateOnACPower=no was ignored because the system does not have a battery."); + else if (on_ac_power() > 0) + hibernate_timestamp = usec_add(now(CLOCK_BOOTTIME), sleep_config->hibernate_delay_usec); + } + usec_t before_timestamp = now(CLOCK_BOOTTIME); suspend_interval = MIN(suspend_interval, usec_sub_unsigned(hibernate_timestamp, before_timestamp)); if (suspend_interval <= 0) |