From: Zbigniew Jędrzejewski-Szmek Date: Mon, 23 Jan 2023 14:43:35 +0000 (+0100) Subject: sleep: do not abort if we try to query capacity of missing battery X-Git-Tag: v253-rc1~21^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7ebbe4a5ce431a2bf03066ec85513c693836550b;p=thirdparty%2Fsystemd.git sleep: do not abort if we try to query capacity of missing battery Fixes #25584. From the issue: Assertion 'capacity >= 0' failed at src/shared/sleep-config.c:58, function PTR_TO_CAPACITY(). Aborting. (gdb) bt The problem is that PTR_TO_CAPACITY(hashmap_get(last_capacity, battery_name)) will abort if it's called with a name not present in the hashmap. We want to skip the device silently in this case instead. --- diff --git a/src/shared/sleep-config.c b/src/shared/sleep-config.c index 9c5602d617d..84082214ae1 100644 --- a/src/shared/sleep-config.c +++ b/src/shared/sleep-config.c @@ -495,7 +495,7 @@ int get_total_suspend_interval(Hashmap *last_capacity, usec_t *ret) { continue; } - battery_last_capacity = PTR_TO_CAPACITY(hashmap_get(last_capacity, battery_name)); + battery_last_capacity = get_capacity_by_name(last_capacity, battery_name); if (battery_last_capacity <= 0) continue;