#include <unistd.h>
#include <errno.h>
#include <sys/wait.h>
+#include <sys/stat.h>
#include "libsysfs/sysfs/libsysfs.h"
#include "list.h"
pos = getenv(attr);
if (pos == NULL)
break;
- strlcat(string, pos, maxsize);
dbg("substitute env '%s=%s'", attr, pos);
+ strlcat(string, pos, maxsize);
break;
default:
err("unknown substitution type=%i", type);
static int match_key(const char *key_name, struct udev_rule *rule, struct key *key, const char *val)
{
int match;
+ char value[PATH_SIZE];
char *key_value;
+ char *pos;
if (key->operation == KEY_OP_UNSET)
return 0;
- key_value = rule->buf + key->val_off;
+ strlcpy(value, rule->buf + key->val_off, sizeof(value));
+ key_value = value;
- dbg("check for %s '%s' <-> '%s'", key_name, key_value, val);
- match = (strcmp_pattern(key_value, val) == 0);
- if (match && (key->operation != KEY_OP_NOMATCH)) {
- dbg("%s is matching (matching value)", key_name);
- return 0;
- }
- if (!match && (key->operation == KEY_OP_NOMATCH)) {
- dbg("%s is matching, (non matching value)", key_name);
- return 0;
+ dbg("key %s value='%s'", key_name, key_value);
+ while (key_value) {
+ pos = strchr(key_value, '|');
+ if (pos) {
+ pos[0] = '\0';
+ pos++;
+ }
+ dbg("match %s '%s' <-> '%s'", key_name, key_value, val);
+ match = (strcmp_pattern(key_value, val) == 0);
+ if (match && (key->operation != KEY_OP_NOMATCH)) {
+ dbg("%s is true (matching value)", key_name);
+ return 0;
+ }
+ if (!match && (key->operation == KEY_OP_NOMATCH)) {
+ dbg("%s is true (non-matching value)", key_name);
+ return 0;
+ }
+ key_value = pos;
}
-
- dbg("%s is not matching", key_name);
+ dbg("%s is false", key_name);
return -1;
}
match = (wait_for_sysfs(udev, key_val(rule, &rule->wait_for_sysfs), 3) == 0);
if (match && (rule->wait_for_sysfs.operation != KEY_OP_NOMATCH)) {
- dbg("WAIT_FOR_SYSFS is matching (matching value)");
+ dbg("WAIT_FOR_SYSFS is true (matching value)");
return 0;
}
if (!match && (rule->wait_for_sysfs.operation == KEY_OP_NOMATCH)) {
- dbg("WAIT_FOR_SYSFS is matching, (non matching value)");
+ dbg("WAIT_FOR_SYSFS is true, (non matching value)");
return 0;
}
- dbg("WAIT_FOR_SYSFS is not matching");
+ dbg("WAIT_FOR_SYSFS is false");
return -1;
}
apply_format(udev, program, sizeof(program), class_dev, sysfs_device);
dbg("check for PROGRAM program='%s", program);
if (execute_program(program, udev->subsystem, result, sizeof(result), NULL) != 0) {
- dbg("PROGRAM is not matching");
+ dbg("PROGRAM is false");
if (rule->program.operation != KEY_OP_NOMATCH)
goto exit;
} else {
struct sysfs_class_device *class_dev_parent;
struct sysfs_device *sysfs_device = NULL;
struct udev_rule *rule;
+ int name_set = 0;
dbg("class_dev->name='%s'", class_dev->name);
if (rule == NULL)
break;
- if (udev->name_set && rule->name.operation != KEY_OP_UNSET) {
+ if (name_set && rule->name.operation != KEY_OP_UNSET) {
dbg("node name already set, rule ignored");
continue;
}
/* add multiple symlinks separated by spaces */
pos = temp;
- next = strchr(temp, ' ');
+ while (isspace(pos[0]))
+ pos++;
+ next = strchr(pos, ' ');
while (next) {
next[0] = '\0';
info("add symlink '%s'", pos);
name_list_add(&udev->symlink_list, pos, 0);
+ while (isspace(next[1]))
+ next++;
pos = &next[1];
next = strchr(pos, ' ');
}
- info("add symlink '%s'", pos);
- name_list_add(&udev->symlink_list, pos, 0);
+ if (pos[0] != '\0') {
+ info("add symlink '%s'", pos);
+ name_list_add(&udev->symlink_list, pos, 0);
+ }
}
/* set name, later rules with name set will be ignored */
if (rule->name.operation != KEY_OP_UNSET) {
- udev->name_set = 1;
+ name_set = 1;
strlcpy(udev->name, key_val(rule, &rule->name), sizeof(udev->name));
apply_format(udev, udev->name, sizeof(udev->name), class_dev, sysfs_device);
}
}
- if (udev->name[0] == '\0') {
+ if (!name_set) {
strlcpy(udev->name, udev->kernel_name, sizeof(udev->name));
info("no rule found, will use kernel name '%s'", udev->name);
}