if (*str[0] == '{') {
pos = strchr(*str, '}');
if (pos == NULL) {
- dbg("missing closing brace for format");
+ err("missing closing brace for format");
return NULL;
}
pos[0] = '\0';
dbg("format length=%i", num);
return num;
} else {
- dbg("format parsing error '%s'", *str);
+ err("format parsing error '%s'", *str);
}
}
return -1;
cpos++;
}
if (i > 0) {
- dbg("requested part of result string not found");
+ err("requested part of result string not found");
break;
}
strlcpy(temp2, cpos, sizeof(temp2));
}
tmpattr = find_sysfs_attribute(class_dev, sysfs_device, attr);
if (tmpattr == NULL) {
- dbg("sysfa attribute '%s' not found", attr);
+ dbg("sysfs attribute '%s' not found", attr);
break;
}
/* strip trailing whitespace of matching value */
dbg("substitute udev_root '%s'", udev_root);
break;
default:
- dbg("unknown substitution type '%%%c'", c);
+ err("unknown substitution type '%%%c'", c);
break;
}
/* truncate to specified length */
retval = pipe(fds);
if (retval != 0) {
- dbg("pipe failed");
+ err("pipe failed");
return -1;
}
info(KEY_PROGRAM " execution of '%s' failed", path);
exit(1);
case -1:
- dbg("fork failed");
+ err("fork of '%s' failed", path);
return -1;
default:
/* parent reads from fds[0] */
i += count;
if (i >= len-1) {
- dbg("result len %d too short", len);
+ err("result len %d too short", len);
retval = -1;
break;
}
}
if (count < 0) {
- dbg("read failed with '%s'", strerror(errno));
+ err("read failed with '%s'", strerror(errno));
retval = -1;
}
return 0;
}
-static int match_sysfs_pairs(struct udev_rule *rule, struct sysfs_class_device *class_dev, struct sysfs_device *sysfs_device)
-{
- int i;
-
- for (i = 0; i < rule->sysfs_pair_count; i++) {
- struct key_pair *pair;
-
- pair = &rule->sysfs_pair[i];
- if ((pair->name[0] == '\0') || (pair->value[0] == '\0'))
- break;
- if (compare_sysfs_attribute(class_dev, sysfs_device, pair) != 0) {
- dbg("sysfs pair #%u does not match", i);
- if (pair->operation != KEY_OP_NOMATCH)
- return -1;
- } else {
- dbg("sysfs pair #%u matches", i);
- if (pair->operation == KEY_OP_NOMATCH)
- return -1;
- }
- }
-
- return 0;
-}
-
-static int match_id(struct udev_rule *rule, struct sysfs_device *sysfs_device)
-{
- char path[PATH_SIZE];
- char *temp;
-
- strlcpy(path, sysfs_device->path, sizeof(path));
- temp = strrchr(path, '/');
- temp++;
- dbg("search '%s' in '%s', path='%s'", rule->id, temp, path);
- if (strcmp_pattern(rule->id, temp) != 0)
- return -ENODEV;
-
- return 0;
-}
-
static int match_rule(struct udevice *udev, struct udev_rule *rule,
struct sysfs_class_device *class_dev, struct sysfs_device *sysfs_device)
{
dbg(KEY_SUBSYSTEM " key is true");
}
+ if (rule->env_pair_count) {
+ int i;
+
+ dbg("check for " KEY_ENV " pairs");
+ for (i = 0; i < rule->env_pair_count; i++) {
+ struct key_pair *pair;
+ const char *value;
+
+ pair = &rule->env_pair[i];
+ value = getenv(pair->name);
+ if (!value) {
+ dbg(KEY_ENV "{'%s'} is not found", pair->name);
+ goto exit;
+ }
+ if (strcmp_pattern(pair->value, value) != 0) {
+ dbg(KEY_ENV "{'%s'} is not matching", pair->name);
+ if (pair->operation != KEY_OP_NOMATCH)
+ goto exit;
+ } else {
+ dbg(KEY_ENV "{'%s'} matches", pair->name);
+ if (pair->operation == KEY_OP_NOMATCH)
+ goto exit;
+ }
+ }
+ dbg(KEY_ENV " key is true");
+ }
+
/* walk up the chain of physical devices and find a match */
while (1) {
/* check for matching driver */
if (rule->driver[0] != '\0') {
if (sysfs_device == NULL) {
dbg("device has no sysfs_device");
- goto try_parent;
+ goto exit;
}
dbg("check for " KEY_DRIVER " rule->driver='%s' sysfs_device->driver_name='%s'",
rule->driver, sysfs_device->driver_name);
if (rule->bus[0] != '\0') {
if (sysfs_device == NULL) {
dbg("device has no sysfs_device");
- goto try_parent;
+ goto exit;
}
dbg("check for " KEY_BUS " rule->bus='%s' sysfs_device->bus='%s'",
rule->bus, sysfs_device->bus);
if (rule->id[0] != '\0') {
if (sysfs_device == NULL) {
dbg("device has no sysfs_device");
- goto try_parent;
+ goto exit;
}
dbg("check " KEY_ID);
- if (match_id(rule, sysfs_device) != 0) {
+ if (strcmp_pattern(rule->id, sysfs_device->bus_id) != 0) {
dbg(KEY_ID " is not matching");
if (rule->id_operation != KEY_OP_NOMATCH)
goto try_parent;
}
/* check for matching sysfs pairs */
- if (rule->sysfs_pair[0].name[0] != '\0') {
+ if (rule->sysfs_pair_count) {
+ int i;
+
dbg("check " KEY_SYSFS " pairs");
- if (match_sysfs_pairs(rule, class_dev, sysfs_device) != 0) {
- dbg(KEY_SYSFS " is not matching");
- goto try_parent;
+ for (i = 0; i < rule->sysfs_pair_count; i++) {
+ struct key_pair *pair;
+
+ pair = &rule->sysfs_pair[i];
+ if (compare_sysfs_attribute(class_dev, sysfs_device, pair) != 0) {
+ dbg(KEY_SYSFS "{'%s'} is not matching", pair->name);
+ if (pair->operation != KEY_OP_NOMATCH)
+ goto try_parent;
+ } else {
+ dbg(KEY_SYSFS "{'%s'} matches", pair->name);
+ if (pair->operation == KEY_OP_NOMATCH)
+ goto try_parent;
+ }
}
dbg(KEY_SYSFS " keys are true");
}
sysfs_device = sysfs_get_device_parent(sysfs_device);
if (sysfs_device == NULL)
goto exit;
- dbg("sysfs_device->path='%s'", sysfs_device->path);
- dbg("sysfs_device->bus_id='%s'", sysfs_device->bus_id);
+ dbg("look at sysfs_device->path='%s'", sysfs_device->path);
+ dbg("look at sysfs_device->bus_id='%s'", sysfs_device->bus_id);
}
/* execute external program */
next = strchr(temp, ' ');
while (next) {
next[0] = '\0';
- dbg("add symlink '%s'", pos);
+ info("add symlink '%s'", pos);
name_list_add(&udev->symlink_list, pos, 0);
pos = &next[1];
next = strchr(pos, ' ');
}
- dbg("add symlink '%s'", pos);
+ info("add symlink '%s'", pos);
name_list_add(&udev->symlink_list, pos, 0);
}
if (udev->name[0] == '\0') {
/* no rule matched, so we use the kernel name */
strlcpy(udev->name, udev->kernel_name, sizeof(udev->name));
- dbg("no rule found, use kernel name '%s'", udev->name);
+ info("no rule found, use kernel name '%s'", udev->name);
}
if (udev->tmp_node[0] != '\0') {