]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sleep: do not abort if we try to query capacity of missing battery
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 23 Jan 2023 14:43:35 +0000 (15:43 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 23 Jan 2023 21:05:36 +0000 (22:05 +0100)
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.

src/shared/sleep-config.c

index 9c5602d617d21929ad945ed455599ba26db08875..84082214ae176a2317b82ff301d0c9cf7ed6adcb 100644 (file)
@@ -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;