/*
* udev_rules.c
*
- * Userspace devfs
- *
* Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
* Copyright (C) 2003-2005 Kay Sievers <kay.sievers@vrfy.org>
*
- *
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation version 2 of the License.
#include "udev_db.h"
-/* compare string with pattern (supports * ? [0-9] [!A-Z]) */
-static int strcmp_pattern(const char *p, const char *s)
-{
- if (s[0] == '\0') {
- while (p[0] == '*')
- p++;
- return (p[0] != '\0');
- }
- switch (p[0]) {
- case '[':
- {
- int not = 0;
- p++;
- if (p[0] == '!') {
- not = 1;
- p++;
- }
- while ((p[0] != '\0') && (p[0] != ']')) {
- int match = 0;
- if (p[1] == '-') {
- if ((s[0] >= p[0]) && (s[0] <= p[2]))
- match = 1;
- p += 3;
- } else {
- match = (p[0] == s[0]);
- p++;
- }
- if (match ^ not) {
- while ((p[0] != '\0') && (p[0] != ']'))
- p++;
- if (p[0] == ']')
- return strcmp_pattern(p+1, s+1);
- }
- }
- }
- break;
- case '*':
- if (strcmp_pattern(p, s+1))
- return strcmp_pattern(p+1, s);
- return 0;
- case '\0':
- if (s[0] == '\0') {
- return 0;
- }
- break;
- default:
- if ((p[0] == s[0]) || (p[0] == '?'))
- return strcmp_pattern(p+1, s+1);
- break;
- }
- return 1;
-}
-
/* extract possible {attr} and move str behind it */
static char *get_format_attribute(char **str)
{
if (bufline[0] == COMMENT_CHARACTER)
continue;
- strlcpy(line, bufline, count+1);
+ memcpy(line, bufline, count);
+ line[count] = '\0';
linepos = line;
if (get_key(&linepos, &variable, &value) == 0) {
static int find_sysfs_attribute(struct sysfs_class_device *class_dev, struct sysfs_device *sysfs_device,
const char *name, char *value, size_t len)
{
+ struct sysfs_class_device *class_dev_parent;
struct sysfs_attribute *tmpattr;
dbg("look for device attribute '%s'", name);
tmpattr = sysfs_get_classdev_attr(class_dev, name);
if (tmpattr)
goto attr_found;
+ class_dev_parent = sysfs_get_classdev_parent(class_dev);
+ if (class_dev_parent) {
+ tmpattr = sysfs_get_classdev_attr(class_dev_parent, name);
+ if (tmpattr)
+ goto attr_found;
+ }
}
if (sysfs_device) {
dbg("look for devices attribute '%s/%s'", sysfs_device->path, name);
const char *value = getenv(key_name);
if (!value) {
- dbg("ENV{'%s'} is not found", key_name);
- goto exit;
+ dbg("ENV{'%s'} is not set", key_name);
+ value = "";
}
if (match_key("ENV", rule, &pair->key, value))
goto exit;
dbg("last rule to be applied");
break;
}
+
+ if (rule->goto_label.operation != KEY_OP_UNSET) {
+ dbg("moving forward to label '%s'", key_val(rule, &rule->goto_label));
+ udev_rules_iter_label(rules, key_val(rule, &rule->goto_label));
+ }
}
}
return 0;
}
-int udev_rules_get_run(struct udev_rules *rules, struct udevice *udev, struct sysfs_device *sysfs_device)
+int udev_rules_get_run(struct udev_rules *rules, struct udevice *udev,
+ struct sysfs_class_device *class_dev, struct sysfs_device *sysfs_dev)
{
struct udev_rule *rule;
+ if (class_dev && !sysfs_dev)
+ sysfs_dev = sysfs_get_classdev_device(class_dev);
+ if (sysfs_dev) {
+ dbg("found devices device: path='%s', bus_id='%s', bus='%s'",
+ sysfs_dev->path, sysfs_dev->bus_id, sysfs_dev->bus);
+ strlcpy(udev->bus_id, sysfs_dev->bus_id, sizeof(udev->bus_id));
+ }
+
+ dbg("udev->kernel_name='%s'", udev->kernel_name);
+
/* look for a matching rule to apply */
udev_rules_iter_init(rules);
while (1) {
continue;
}
- if (match_rule(udev, rule, NULL, sysfs_device) == 0) {
+ if (match_rule(udev, rule, class_dev, sysfs_dev) == 0) {
if (rule->ignore_device) {
info("rule applied, '%s' is ignored", udev->kernel_name);
udev->ignore_device = 1;
}
}
strlcpy(program, key_val(rule, &rule->run), sizeof(program));
- apply_format(udev, program, sizeof(program), NULL, sysfs_device);
+ apply_format(udev, program, sizeof(program), class_dev, sysfs_dev);
dbg("add run '%s'", program);
name_list_add(&udev->run_list, program, 0);
if (rule->run.operation == KEY_OP_ASSIGN_FINAL)
dbg("last rule to be applied");
break;
}
+
+ if (rule->goto_label.operation != KEY_OP_UNSET) {
+ dbg("moving forward to label '%s'", key_val(rule, &rule->goto_label));
+ udev_rules_iter_label(rules, key_val(rule, &rule->goto_label));
+ }
}
}