From: Zbigniew Jędrzejewski-Szmek Date: Tue, 23 Aug 2022 14:48:26 +0000 (+0200) Subject: on-ac-power: ignore devices with scope==Device X-Git-Tag: v252-rc1~356^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3c69e94a5ce8076fa1240028f24d9b4ba1b67408;p=thirdparty%2Fsystemd.git on-ac-power: ignore devices with scope==Device My mouse is reported as: P: /devices/pci0000:00/0000:00:14.0/usb1/1-4/1-4.4/1-4.4:1.2/0003:046D:C52B.001E/0003:046D:4051.001F/power_supply/hidpp_battery_4 M: hidpp_battery_4 R: 4 U: power_supply E: DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-4/1-4.4/1-4.4:1.2/0003:046D:C52B.001E/0003:046D:4051.001F/power_supply/hidpp_battery_4 E: SUBSYSTEM=power_supply E: POWER_SUPPLY_NAME=hidpp_battery_4 E: POWER_SUPPLY_TYPE=Battery E: POWER_SUPPLY_ONLINE=1 E: POWER_SUPPLY_STATUS=Discharging E: POWER_SUPPLY_SCOPE=Device E: POWER_SUPPLY_MODEL_NAME=Wireless Mouse M510 E: POWER_SUPPLY_MANUFACTURER=Logitech E: POWER_SUPPLY_SERIAL_NUMBER=4051-bc-cd-d2-5b E: POWER_SUPPLY_CAPACITY_LEVEL=Normal See https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=25a0bc2dfc2ea732f40af2dae52426ead66ae76e Effectively, "System" and "Unkown" are passed through, "Device" is rejected. --- diff --git a/src/shared/udev-util.c b/src/shared/udev-util.c index 8892d2bc9a9..2845e62c79c 100644 --- a/src/shared/udev-util.c +++ b/src/shared/udev-util.c @@ -704,6 +704,14 @@ int on_ac_power(void) { bool is_battery = streq(val, "Battery"); if (is_battery) { + r = sd_device_get_sysattr_value(d, "scope", &val); + if (r < 0) + log_device_debug_errno(d, r, "Failed to read 'scope' sysfs attribute, ignoring: %m"); + else if (streq(val, "Device")) { + log_device_debug(d, "The power supply is a device battery, ignoring."); + continue; + } + found_battery = true; log_device_debug(d, "The power supply is battery."); continue;