]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
on-ac-power: ignore devices with scope==Device 24420/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 23 Aug 2022 14:48:26 +0000 (16:48 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 23 Aug 2022 15:04:31 +0000 (17:04 +0200)
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.

src/shared/udev-util.c

index 8892d2bc9a9134d94d5fd5a17c12565ab118d276..2845e62c79cd714cd05fd787a24ce51e2b92d5ee 100644 (file)
@@ -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;