udev: use sd_device for udev_event.dev_parent

This commit is contained in:
Yu Watanabe 2018-10-29 15:16:00 +09:00
parent 5ba7e79885
commit f3d241feb2
3 changed files with 21 additions and 13 deletions

View file

@ -159,7 +159,7 @@ static ssize_t subst_format_var(struct udev_event *event,
case SUBST_ID:
if (!event->dev_parent)
return 0;
r = sd_device_get_sysname(event->dev_parent->device, &val);
r = sd_device_get_sysname(event->dev_parent, &val);
if (r < 0)
return r;
l = strpcpy(&s, l, val);
@ -167,7 +167,7 @@ static ssize_t subst_format_var(struct udev_event *event,
case SUBST_DRIVER:
if (!event->dev_parent)
return 0;
r = sd_device_get_driver(event->dev_parent->device, &val);
r = sd_device_get_driver(event->dev_parent, &val);
if (r < 0)
return r == -ENOENT ? 0 : r;
l = strpcpy(&s, l, val);
@ -240,8 +240,8 @@ static ssize_t subst_format_var(struct udev_event *event,
(void) sd_device_get_sysattr_value(dev, attr, &val);
/* try to read the attribute of the parent device, other matches have selected */
if (!val && event->dev_parent && event->dev_parent->device != dev)
(void) sd_device_get_sysattr_value(event->dev_parent->device, attr, &val);
if (!val && event->dev_parent && event->dev_parent != dev)
(void) sd_device_get_sysattr_value(event->dev_parent, attr, &val);
if (!val)
return 0;

View file

@ -1861,32 +1861,39 @@ int udev_rules_apply_to_event(
next++;
/* loop over parents */
event->dev_parent = event->dev;
event->dev_parent = event->dev->device;
for (;;) {
struct token *key;
const char *val;
/* loop over sequence of parent match keys */
for (key = cur; key < next; key++ ) {
dump_token(rules, key);
switch(key->type) {
case TK_M_KERNELS:
if (match_key(rules, key, udev_device_get_sysname(event->dev_parent)) != 0)
if (sd_device_get_sysname(event->dev_parent, &val) < 0)
goto try_parent;
if (match_key(rules, key, val) != 0)
goto try_parent;
break;
case TK_M_SUBSYSTEMS:
if (match_key(rules, key, udev_device_get_subsystem(event->dev_parent)) != 0)
if (sd_device_get_subsystem(event->dev_parent, &val) < 0)
goto try_parent;
if (match_key(rules, key, val) != 0)
goto try_parent;
break;
case TK_M_DRIVERS:
if (match_key(rules, key, udev_device_get_driver(event->dev_parent)) != 0)
if (sd_device_get_driver(event->dev_parent, &val) < 0)
goto try_parent;
if (match_key(rules, key, val) != 0)
goto try_parent;
break;
case TK_M_ATTRS:
if (match_attr(rules, event->dev_parent->device, event, key) != 0)
if (match_attr(rules, event->dev_parent, event, key) != 0)
goto try_parent;
break;
case TK_M_TAGS: {
bool match = udev_device_has_tag(event->dev_parent, rules_str(rules, cur->key.value_off));
bool match = sd_device_has_tag(event->dev_parent, rules_str(rules, cur->key.value_off));
if (match && key->key.op == OP_NOMATCH)
goto try_parent;
@ -1901,9 +1908,10 @@ int udev_rules_apply_to_event(
break;
try_parent:
event->dev_parent = udev_device_get_parent(event->dev_parent);
if (event->dev_parent == NULL)
if (sd_device_get_parent(event->dev_parent, &event->dev_parent) < 0) {
event->dev_parent = NULL;
goto nomatch;
}
}
/* move behind our sequence of parent match keys */
cur = next;

View file

@ -22,7 +22,7 @@
struct udev_event {
struct udev_device *dev;
struct udev_device *dev_parent;
sd_device *dev_parent;
sd_device *dev_db_clone;
char *name;
char *program_result;