]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-device: introduce device_get_property_bool()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 28 Apr 2022 12:37:59 +0000 (21:37 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 29 Apr 2022 19:14:10 +0000 (04:14 +0900)
src/libsystemd/sd-device/device-private.h
src/libsystemd/sd-device/sd-device.c

index b6b36b67270933ecf2d5293fb5df06d49abf53a5..5160f580069c0346dc240d2814aa7392e1a076d4 100644 (file)
@@ -17,6 +17,7 @@ static inline int device_new_from_watch_handle(sd_device **ret, int wd) {
         return device_new_from_watch_handle_at(ret, -1, wd);
 }
 
+int device_get_property_bool(sd_device *device, const char *key);
 int device_get_device_id(sd_device *device, const char **ret);
 int device_get_devlink_priority(sd_device *device, int *ret);
 int device_get_watch_handle(sd_device *device);
index c7f4c48d421e247c6916d9ab769ca744baaf0074..0bfcdcdf2d9275a78435be555fa927732a51415f 100644 (file)
@@ -2007,6 +2007,20 @@ _public_ int sd_device_get_property_value(sd_device *device, const char *key, co
         return 0;
 }
 
+int device_get_property_bool(sd_device *device, const char *key) {
+        const char *value;
+        int r;
+
+        assert(device);
+        assert(key);
+
+        r = sd_device_get_property_value(device, key, &value);
+        if (r < 0)
+                return r;
+
+        return parse_boolean(value);
+}
+
 _public_ int sd_device_get_trigger_uuid(sd_device *device, sd_id128_t *ret) {
         const char *s;
         sd_id128_t id;
@@ -2296,7 +2310,7 @@ _public_ int sd_device_trigger_with_uuid(
 
 _public_ int sd_device_open(sd_device *device, int flags) {
         _cleanup_close_ int fd = -1, fd2 = -1;
-        const char *devname, *subsystem = NULL, *val = NULL;
+        const char *devname, *subsystem = NULL;
         uint64_t q, diskseq = 0;
         struct stat st;
         dev_t devnum;
@@ -2338,11 +2352,10 @@ _public_ int sd_device_open(sd_device *device, int flags) {
         if (FLAGS_SET(flags, O_PATH))
                 return TAKE_FD(fd);
 
-        r = sd_device_get_property_value(device, "ID_IGNORE_DISKSEQ", &val);
+        r = device_get_property_bool(device, "ID_IGNORE_DISKSEQ");
         if (r < 0 && r != -ENOENT)
                 return r;
-
-        if (!val || parse_boolean(val) <= 0) {
+        if (r <= 0) {
                 r = sd_device_get_diskseq(device, &diskseq);
                 if (r < 0 && r != -ENOENT)
                         return r;