udev-rules: make match_attr() take sd_device instead of udev_device
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 29 Oct 2018 06:15:25 +0000 (15:15 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 7 Nov 2018 04:35:03 +0000 (13:35 +0900)
src/udev/udev-rules.c

index d5ebd3b..daa3fd2 100644 (file)
@@ -1673,11 +1673,9 @@ static int match_key(struct udev_rules *rules, struct token *token, const char *
         return -1;
 }
 
-static int match_attr(struct udev_rules *rules, struct udev_device *dev, struct udev_event *event, struct token *cur) {
-        const char *name;
-        char nbuf[UTIL_NAME_SIZE];
-        const char *value;
-        char vbuf[UTIL_NAME_SIZE];
+static int match_attr(struct udev_rules *rules, sd_device *dev, struct udev_event *event, struct token *cur) {
+        char nbuf[UTIL_NAME_SIZE], vbuf[UTIL_NAME_SIZE];
+        const char *name, *value;
         size_t len;
 
         name = rules_str(rules, cur->key.attr_off);
@@ -1687,8 +1685,7 @@ static int match_attr(struct udev_rules *rules, struct udev_device *dev, struct
                 name = nbuf;
                 _fallthrough_;
         case SB_NONE:
-                value = udev_device_get_sysattr_value(dev, name);
-                if (value == NULL)
+                if (sd_device_get_sysattr_value(dev, name, &value) < 0)
                         return -1;
                 break;
         case SB_SUBSYS:
@@ -1831,7 +1828,7 @@ int udev_rules_apply_to_event(
                                 goto nomatch;
                         break;
                 case TK_M_ATTR:
-                        if (match_attr(rules, event->dev, event, cur) != 0)
+                        if (match_attr(rules, event->dev->device, event, cur) != 0)
                                 goto nomatch;
                         break;
                 case TK_M_SYSCTL: {
@@ -1885,7 +1882,7 @@ int udev_rules_apply_to_event(
                                                         goto try_parent;
                                                 break;
                                         case TK_M_ATTRS:
-                                                if (match_attr(rules, event->dev_parent, event, key) != 0)
+                                                if (match_attr(rules, event->dev_parent->device, event, key) != 0)
                                                         goto try_parent;
                                                 break;
                                         case TK_M_TAGS: {