]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev-rules: make import_property_from_string() take sd_device
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 29 Oct 2018 06:24:14 +0000 (15:24 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 7 Nov 2018 04:35:03 +0000 (13:35 +0900)
Also, this makes the function return negative errno, though its
return value is always ignored.

src/udev/udev-rules.c

index cf1c44236f3a006dedf4ceb54ed6fe903641fbaf..5c046ea838f25c7ade7b0f0b1a5441162cd96870 100644 (file)
@@ -16,6 +16,7 @@
 #include "alloc-util.h"
 #include "conf-files.h"
 #include "def.h"
+#include "device-private.h"
 #include "device-util.h"
 #include "dirent-util.h"
 #include "escape.h"
@@ -557,7 +558,7 @@ static gid_t add_gid(struct udev_rules *rules, const char *group) {
         return gid;
 }
 
-static int import_property_from_string(struct udev_device *dev, char *line) {
+static int import_property_from_string(sd_device *dev, char *line) {
         char *key;
         char *val;
         size_t len;
@@ -569,12 +570,12 @@ static int import_property_from_string(struct udev_device *dev, char *line) {
 
         /* comment or empty line */
         if (IN_SET(key[0], '#', '\0'))
-                return -1;
+                return 0;
 
         /* split key/value */
         val = strchr(key, '=');
-        if (val == NULL)
-                return -1;
+        if (!val)
+                return -EINVAL;
         val[0] = '\0';
         val++;
 
@@ -585,7 +586,7 @@ static int import_property_from_string(struct udev_device *dev, char *line) {
         /* terminate key */
         len = strlen(key);
         if (len == 0)
-                return -1;
+                return -EINVAL;
         while (isspace(key[len-1]))
                 len--;
         key[len] = '\0';
@@ -593,27 +594,25 @@ static int import_property_from_string(struct udev_device *dev, char *line) {
         /* terminate value */
         len = strlen(val);
         if (len == 0)
-                return -1;
+                return -EINVAL;
         while (isspace(val[len-1]))
                 len--;
         val[len] = '\0';
 
         if (len == 0)
-                return -1;
+                return -EINVAL;
 
         /* unquote */
         if (IN_SET(val[0], '"', '\'')) {
                 if (len == 1 || val[len-1] != val[0]) {
                         log_debug("inconsistent quoting: '%s', skip", line);
-                        return -1;
+                        return -EINVAL;
                 }
                 val[len-1] = '\0';
                 val++;
         }
 
-        udev_device_add_property(dev, key, val);
-
-        return 0;
+        return device_add_property(dev, key, val);
 }
 
 static int import_file_into_properties(struct udev_device *dev, const char *filename) {
@@ -633,7 +632,7 @@ static int import_file_into_properties(struct udev_device *dev, const char *file
                 if (r == 0)
                         break;
 
-                (void) import_property_from_string(dev, line);
+                (void) import_property_from_string(dev->device, line);
         }
 
         return 0;
@@ -660,7 +659,7 @@ static int import_program_into_properties(struct udev_event *event,
                         pos[0] = '\0';
                         pos = &pos[1];
                 }
-                (void) import_property_from_string(event->dev, line);
+                (void) import_property_from_string(event->dev->device, line);
                 line = pos;
         }
         return 0;