mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-09-10 21:45:21 +03:00
[PATCH] simplify sysfs_pair handling
This commit is contained in:
committed by
Greg KH
parent
38285d23d7
commit
79f651f4bd
19
udev_rules.c
19
udev_rules.c
@@ -463,16 +463,16 @@ attr_found:
|
|||||||
return tmpattr;
|
return tmpattr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int compare_sysfs_attribute(struct sysfs_class_device *class_dev, struct sysfs_device *sysfs_device, struct sysfs_pair *pair)
|
static int compare_sysfs_attribute(struct sysfs_class_device *class_dev, struct sysfs_device *sysfs_device, struct key_pair *pair)
|
||||||
{
|
{
|
||||||
struct sysfs_attribute *tmpattr;
|
struct sysfs_attribute *tmpattr;
|
||||||
int i;
|
int i;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
if ((pair == NULL) || (pair->file[0] == '\0') || (pair->value == '\0'))
|
if ((pair == NULL) || (pair->name[0] == '\0') || (pair->value == '\0'))
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
||||||
tmpattr = find_sysfs_attribute(class_dev, sysfs_device, pair->file);
|
tmpattr = find_sysfs_attribute(class_dev, sysfs_device, pair->name);
|
||||||
if (tmpattr == NULL)
|
if (tmpattr == NULL)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
||||||
@@ -489,23 +489,24 @@ static int compare_sysfs_attribute(struct sysfs_class_device *class_dev, struct
|
|||||||
}
|
}
|
||||||
|
|
||||||
dbg("compare attribute '%s' value '%s' with '%s'",
|
dbg("compare attribute '%s' value '%s' with '%s'",
|
||||||
pair->file, tmpattr->value, pair->value);
|
pair->name, tmpattr->value, pair->value);
|
||||||
if (strcmp_pattern(pair->value, tmpattr->value) != 0)
|
if (strcmp_pattern(pair->value, tmpattr->value) != 0)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
||||||
dbg("found matching attribute '%s' with value '%s'",
|
dbg("found matching attribute '%s' with value '%s'",
|
||||||
pair->file, pair->value);
|
pair->name, pair->value);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int match_sysfs_pairs(struct udev_rule *rule, struct sysfs_class_device *class_dev, struct sysfs_device *sysfs_device)
|
static int match_sysfs_pairs(struct udev_rule *rule, struct sysfs_class_device *class_dev, struct sysfs_device *sysfs_device)
|
||||||
{
|
{
|
||||||
struct sysfs_pair *pair;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < MAX_SYSFS_PAIRS; ++i) {
|
for (i = 0; i < rule->sysfs_pair_count; i++) {
|
||||||
|
struct key_pair *pair;
|
||||||
|
|
||||||
pair = &rule->sysfs_pair[i];
|
pair = &rule->sysfs_pair[i];
|
||||||
if ((pair->file[0] == '\0') || (pair->value[0] == '\0'))
|
if ((pair->name[0] == '\0') || (pair->value[0] == '\0'))
|
||||||
break;
|
break;
|
||||||
if (compare_sysfs_attribute(class_dev, sysfs_device, pair) != 0) {
|
if (compare_sysfs_attribute(class_dev, sysfs_device, pair) != 0) {
|
||||||
dbg("sysfs pair #%u does not match", i);
|
dbg("sysfs pair #%u does not match", i);
|
||||||
@@ -631,7 +632,7 @@ static int match_rule(struct udevice *udev, struct udev_rule *rule,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* check for matching sysfs pairs */
|
/* check for matching sysfs pairs */
|
||||||
if (rule->sysfs_pair[0].file[0] != '\0') {
|
if (rule->sysfs_pair[0].name[0] != '\0') {
|
||||||
dbg("check " KEY_SYSFS " pairs");
|
dbg("check " KEY_SYSFS " pairs");
|
||||||
if (match_sysfs_pairs(rule, class_dev, sysfs_device) != 0) {
|
if (match_sysfs_pairs(rule, class_dev, sysfs_device) != 0) {
|
||||||
dbg(KEY_SYSFS " is not matching");
|
dbg(KEY_SYSFS " is not matching");
|
||||||
|
@@ -48,7 +48,7 @@
|
|||||||
#define OPTION_IGNORE_REMOVE "ignore_remove"
|
#define OPTION_IGNORE_REMOVE "ignore_remove"
|
||||||
#define OPTION_PARTITIONS "all_partitions"
|
#define OPTION_PARTITIONS "all_partitions"
|
||||||
|
|
||||||
#define MAX_SYSFS_PAIRS 5
|
#define KEY_SYSFS_PAIRS_MAX 5
|
||||||
|
|
||||||
#define RULEFILE_SUFFIX ".rules"
|
#define RULEFILE_SUFFIX ".rules"
|
||||||
|
|
||||||
@@ -60,8 +60,8 @@ enum key_operation {
|
|||||||
KEY_OP_ASSIGN,
|
KEY_OP_ASSIGN,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sysfs_pair {
|
struct key_pair {
|
||||||
char file[PATH_SIZE];
|
char name[NAME_SIZE];
|
||||||
char value[VALUE_SIZE];
|
char value[VALUE_SIZE];
|
||||||
enum key_operation operation;
|
enum key_operation operation;
|
||||||
};
|
};
|
||||||
@@ -83,7 +83,8 @@ struct udev_rule {
|
|||||||
enum key_operation program_operation;
|
enum key_operation program_operation;
|
||||||
char result[PATH_SIZE];
|
char result[PATH_SIZE];
|
||||||
enum key_operation result_operation;
|
enum key_operation result_operation;
|
||||||
struct sysfs_pair sysfs_pair[MAX_SYSFS_PAIRS];
|
struct key_pair sysfs_pair[KEY_SYSFS_PAIRS_MAX];
|
||||||
|
int sysfs_pair_count;
|
||||||
|
|
||||||
char name[PATH_SIZE];
|
char name[PATH_SIZE];
|
||||||
char symlink[PATH_SIZE];
|
char symlink[PATH_SIZE];
|
||||||
|
@@ -55,7 +55,7 @@ static int add_config_dev(struct udev_rule *rule)
|
|||||||
"owner='%s', group='%s', mode=%#o, "
|
"owner='%s', group='%s', mode=%#o, "
|
||||||
"all_partions=%u, ignore_remove=%u, ignore_device=%u, last_rule=%u",
|
"all_partions=%u, ignore_remove=%u, ignore_device=%u, last_rule=%u",
|
||||||
rule->name, rule->symlink, rule->bus, rule->id,
|
rule->name, rule->symlink, rule->bus, rule->id,
|
||||||
rule->sysfs_pair[0].file, rule->sysfs_pair[0].value,
|
rule->sysfs_pair[0].name, rule->sysfs_pair[0].value,
|
||||||
rule->kernel, rule->program, rule->result, rule->owner, rule->group, rule->mode,
|
rule->kernel, rule->program, rule->result, rule->owner, rule->group, rule->mode,
|
||||||
rule->partitions, rule->ignore_remove, rule->ignore_device, rule->last_rule);
|
rule->partitions, rule->ignore_remove, rule->ignore_device, rule->last_rule);
|
||||||
|
|
||||||
@@ -271,29 +271,24 @@ static int rules_parse(struct udevice *udev, const char *filename)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (strncasecmp(key, KEY_SYSFS, sizeof(KEY_SYSFS)-1) == 0) {
|
if (strncasecmp(key, KEY_SYSFS, sizeof(KEY_SYSFS)-1) == 0) {
|
||||||
struct sysfs_pair *pair = &rule.sysfs_pair[0];
|
struct key_pair *pair;
|
||||||
int sysfs_pair_num = 0;
|
|
||||||
|
|
||||||
/* find first unused pair */
|
if (rule.sysfs_pair_count >= KEY_SYSFS_PAIRS_MAX) {
|
||||||
while (pair->file[0] != '\0') {
|
dbg("skip rule, to many " KEY_SYSFS " keys in a single rule");
|
||||||
++sysfs_pair_num;
|
goto error;
|
||||||
if (sysfs_pair_num >= MAX_SYSFS_PAIRS) {
|
|
||||||
pair = NULL;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
++pair;
|
pair = &rule.sysfs_pair[rule.sysfs_pair_count];
|
||||||
}
|
rule.sysfs_pair_count++;
|
||||||
if (pair) {
|
|
||||||
attr = get_key_attribute(key + sizeof(KEY_SYSFS)-1);
|
attr = get_key_attribute(key + sizeof(KEY_SYSFS)-1);
|
||||||
if (attr == NULL) {
|
if (attr == NULL) {
|
||||||
dbg("error parsing " KEY_SYSFS " attribute");
|
dbg("error parsing " KEY_SYSFS " attribute");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
strlcpy(pair->file, attr, sizeof(pair->file));
|
strlcpy(pair->name, attr, sizeof(pair->name));
|
||||||
strlcpy(pair->value, value, sizeof(pair->value));
|
strlcpy(pair->value, value, sizeof(pair->value));
|
||||||
pair->operation = operation;
|
pair->operation = operation;
|
||||||
valid = 1;
|
valid = 1;
|
||||||
}
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -394,7 +389,7 @@ static int rules_parse(struct udevice *udev, const char *filename)
|
|||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
/* simple plausibility checks for given keys */
|
/* simple plausibility checks for given keys */
|
||||||
if ((rule.sysfs_pair[0].file[0] == '\0') ^
|
if ((rule.sysfs_pair[0].name[0] == '\0') ^
|
||||||
(rule.sysfs_pair[0].value[0] == '\0')) {
|
(rule.sysfs_pair[0].value[0] == '\0')) {
|
||||||
info("inconsistency in " KEY_SYSFS " key");
|
info("inconsistency in " KEY_SYSFS " key");
|
||||||
goto error;
|
goto error;
|
||||||
|
Reference in New Issue
Block a user