]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sleep: enumerate only existing and non-device batteries 25374/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 13 Nov 2022 17:54:50 +0000 (02:54 +0900)
committerLuca Boccassi <bluca@debian.org>
Fri, 27 Jan 2023 20:52:12 +0000 (20:52 +0000)
The enumerator is now mostly consistent with on_ac_power() in
udev-util.c.

src/shared/sleep-config.c

index 056180fe90bf59c6855ccb35573655801e6352d0..232d1db7f58b1c96fbec5da1ccad9e2609811959 100644 (file)
@@ -143,16 +143,27 @@ static int battery_enumerator_new(sd_device_enumerator **ret) {
         if (r < 0)
                 return r;
 
-        r = sd_device_enumerator_add_match_subsystem(e, "power_supply", /* match= */ true);
+        r = sd_device_enumerator_add_match_subsystem(e, "power_supply", /* match = */ true);
         if (r < 0)
                 return r;
 
-        r = sd_device_enumerator_add_match_property(e, "POWER_SUPPLY_TYPE", "Battery");
+        r = sd_device_enumerator_allow_uninitialized(e);
         if (r < 0)
                 return r;
 
-        *ret = TAKE_PTR(e);
+        r = sd_device_enumerator_add_match_sysattr(e, "type", "Battery", /* match = */ true);
+        if (r < 0)
+                return r;
+
+        r = sd_device_enumerator_add_match_sysattr(e, "present", "1", /* match = */ true);
+        if (r < 0)
+                return r;
 
+        r = sd_device_enumerator_add_match_sysattr(e, "scope", "Device", /* match = */ false);
+        if (r < 0)
+                return r;
+
+        *ret = TAKE_PTR(e);
         return 0;
 }