summaryrefslogtreecommitdiffstats
path: root/src/sleep
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2022-11-13 16:09:34 +0100
committerLuca Boccassi <bluca@debian.org>2023-01-26 12:27:52 +0100
commit2ed56afeb3c26596dbe44858559c92307778ff82 (patch)
treeb2694a90e79e1083f1acab60d244fd1ba3837483 /src/sleep
parentsleep: fetch_batteries_capacity_by_name() does not return -ENOENT (diff)
downloadsystemd-2ed56afeb3c26596dbe44858559c92307778ff82.tar.xz
systemd-2ed56afeb3c26596dbe44858559c92307778ff82.zip
sleep: drop unnecessary temporal vaiable and initialization
Diffstat (limited to 'src/sleep')
-rw-r--r--src/sleep/sleep.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c
index a1874c5844..d1c45e264d 100644
--- a/src/sleep/sleep.c
+++ b/src/sleep/sleep.c
@@ -275,7 +275,7 @@ static int custom_timer_suspend(const SleepConfig *sleep_config) {
_cleanup_hashmap_free_ Hashmap *last_capacity = NULL, *current_capacity = NULL;
_cleanup_close_ int tfd = -EBADF;
struct itimerspec ts = {};
- usec_t suspend_interval = sleep_config->hibernate_delay_usec, total_suspend_interval;
+ usec_t suspend_interval;
bool woken_by_timer;
tfd = timerfd_create(CLOCK_BOOTTIME_ALARM, TFD_NONBLOCK|TFD_CLOEXEC);
@@ -287,11 +287,12 @@ static int custom_timer_suspend(const SleepConfig *sleep_config) {
if (r < 0)
return log_error_errno(r, "Error fetching battery capacity percentage: %m");
- r = get_total_suspend_interval(last_capacity, &total_suspend_interval);
- if (r < 0)
+ r = get_total_suspend_interval(last_capacity, &suspend_interval);
+ if (r < 0) {
log_debug_errno(r, "Failed to estimate suspend interval using previous discharge rate, ignoring: %m");
- else
- suspend_interval = total_suspend_interval;
+ /* In case of no battery or any errors, system suspend interval will be set to HibernateDelaySec=. */
+ suspend_interval = sleep_config->hibernate_delay_usec;
+ }
usec_t before_timestamp = now(CLOCK_BOOTTIME);