dcavalca / rpms / systemd

Forked from rpms/systemd 4 months ago
Clone
2aacef
From 49d626105a5739bf7fa725f578d02b8873c282c7 Mon Sep 17 00:00:00 2001
2aacef
From: Yu Watanabe <watanabe.yu+github@gmail.com>
2aacef
Date: Mon, 14 Nov 2022 02:54:50 +0900
2aacef
Subject: [PATCH] sleep: enumerate only existing and non-device batteries
2aacef
2aacef
The enumerator is now mostly consistent with on_ac_power() in
2aacef
udev-util.c.
2aacef
2aacef
(cherry picked from commit fe8e0f8e7989fe5cead5ad0e225dc0888ff10140)
2aacef
2aacef
Related: #2151612
2aacef
---
2aacef
 src/shared/sleep-config.c | 17 ++++++++++++++---
2aacef
 1 file changed, 14 insertions(+), 3 deletions(-)
2aacef
2aacef
diff --git a/src/shared/sleep-config.c b/src/shared/sleep-config.c
2aacef
index 4c08e97c8a..2d55e7c860 100644
2aacef
--- a/src/shared/sleep-config.c
2aacef
+++ b/src/shared/sleep-config.c
2aacef
@@ -143,16 +143,27 @@ static int battery_enumerator_new(sd_device_enumerator **ret) {
2aacef
         if (r < 0)
2aacef
                 return r;
2aacef
 
2aacef
-        r = sd_device_enumerator_add_match_subsystem(e, "power_supply", /* match= */ true);
2aacef
+        r = sd_device_enumerator_add_match_subsystem(e, "power_supply", /* match = */ true);
2aacef
         if (r < 0)
2aacef
                 return r;
2aacef
 
2aacef
-        r = sd_device_enumerator_add_match_property(e, "POWER_SUPPLY_TYPE", "Battery");
2aacef
+        r = sd_device_enumerator_allow_uninitialized(e);
2aacef
         if (r < 0)
2aacef
                 return r;
2aacef
 
2aacef
-        *ret = TAKE_PTR(e);
2aacef
+        r = sd_device_enumerator_add_match_sysattr(e, "type", "Battery", /* match = */ true);
2aacef
+        if (r < 0)
2aacef
+                return r;
2aacef
+
2aacef
+        r = sd_device_enumerator_add_match_sysattr(e, "present", "1", /* match = */ true);
2aacef
+        if (r < 0)
2aacef
+                return r;
2aacef
 
2aacef
+        r = sd_device_enumerator_add_match_sysattr(e, "scope", "Device", /* match = */ false);
2aacef
+        if (r < 0)
2aacef
+                return r;
2aacef
+
2aacef
+        *ret = TAKE_PTR(e);
2aacef
         return 0;
2aacef
 }
2aacef