From 647c44c21a350b1fffd45483c9615d0dd77d9cfe Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 6 Aug 2022 03:42:29 +0900 Subject: [PATCH] udev-util: assume system is running on AC power when no battery found Fixes #24214. (cherry picked from commit 96788d2aa4f4b0b49874b4a240ce47d9e8485d1b) (cherry picked from commit ed2955f8fe194040c3b29fb58e6dc02d397d79d5) --- src/shared/udev-util.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/shared/udev-util.c b/src/shared/udev-util.c index 5c1b4a4470..608f546cff 100644 --- a/src/shared/udev-util.c +++ b/src/shared/udev-util.c @@ -643,7 +643,7 @@ static int device_is_power_sink(sd_device *device) { int on_ac_power(void) { _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; - bool found_offline = false, found_online = false; + bool found_offline = false, found_online = false, found_battery = false; sd_device *d; int r; @@ -674,6 +674,7 @@ int on_ac_power(void) { * for defined power source types. Also see: * https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-power */ if (streq(val, "Battery")) { + found_battery = true; log_device_debug(d, "The power supply is battery, ignoring."); continue; } @@ -714,10 +715,12 @@ int on_ac_power(void) { log_debug("Found at least one online non-battery power supply, system is running on AC power."); else if (!found_offline) log_debug("Found no offline non-battery power supply, assuming system is running on AC power."); + else if (!found_battery) + log_debug("Found no battery, assuming system is running on AC power."); else log_debug("All non-battery power supplies are offline, assuming system is running with battery."); - return found_online || !found_offline; + return found_online || !found_offline || !found_battery; } bool udev_available(void) {