diff options
-rw-r--r-- | udev_rules.c | 50 | ||||
-rw-r--r-- | udev_rules.h | 27 | ||||
-rw-r--r-- | udev_rules_parse.c | 78 |
3 files changed, 63 insertions, 92 deletions
diff --git a/udev_rules.c b/udev_rules.c index 117ffdc2d0..48e22ad3e8 100644 --- a/udev_rules.c +++ b/udev_rules.c @@ -626,33 +626,32 @@ static int match_rule(struct udevice *udev, struct udev_rule *rule, { struct sysfs_device *parent_device = sysfs_device; - if (match_key(KEY_ACTION, rule->action, rule->action_operation, udev->action)) + if (match_key("ACTION", rule->action, rule->action_operation, udev->action)) goto exit; - if (match_key(KEY_KERNEL, rule->kernel_name, rule->kernel_operation, udev->kernel_name)) + if (match_key("KERNEL", rule->kernel_name, rule->kernel_operation, udev->kernel_name)) goto exit; - if (match_key(KEY_SUBSYSTEM, rule->subsystem, rule->subsystem_operation, udev->subsystem)) + if (match_key("SUBSYSTEM", rule->subsystem, rule->subsystem_operation, udev->subsystem)) goto exit; - if (match_key(KEY_DEVPATH, rule->devpath, rule->devpath_operation, udev->devpath)) + if (match_key("DEVPATH", rule->devpath, rule->devpath_operation, udev->devpath)) goto exit; if (rule->modalias_operation != KEY_OP_UNSET) { char value[NAME_SIZE]; if (find_sysfs_attribute(NULL, sysfs_device, "modalias", value, sizeof(value)) != 0) { - dbg(KEY_MODALIAS " value not found"); + dbg("MODALIAS value not found"); goto exit; } - if (match_key(KEY_MODALIAS, rule->modalias, rule->modalias_operation, value)) + if (match_key("MODALIAS", rule->modalias, rule->modalias_operation, value)) goto exit; } 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; @@ -660,14 +659,14 @@ static int match_rule(struct udevice *udev, struct udev_rule *rule, pair = &rule->env_pair[i]; value = getenv(pair->name); if (!value) { - dbg(KEY_ENV "{'%s'} is not found", pair->name); + dbg("ENV{'%s'} is not found", pair->name); goto exit; } - dbg("check %i " KEY_ENV " keys", rule->env_pair_count); + dbg("check %i ENV keys", rule->env_pair_count); if (match_key(pair->name, pair->value, pair->operation, value)) goto exit; } - dbg("all %i " KEY_ENV " keys matched", rule->env_pair_count); + dbg("all %i ENV keys matched", rule->env_pair_count); } /* walk up the chain of physical devices and find a match */ @@ -678,7 +677,7 @@ static int match_rule(struct udevice *udev, struct udev_rule *rule, dbg("device has no sysfs_device"); goto exit; } - if (match_key(KEY_BUS, rule->driver, rule->driver_operation, parent_device->driver_name)) + if (match_key("DRIVER", rule->driver, rule->driver_operation, parent_device->driver_name)) goto try_parent; } @@ -688,7 +687,7 @@ static int match_rule(struct udevice *udev, struct udev_rule *rule, dbg("device has no sysfs_device"); goto exit; } - if (match_key(KEY_BUS, rule->bus, rule->bus_operation, parent_device->bus)) + if (match_key("BUS", rule->bus, rule->bus_operation, parent_device->bus)) goto try_parent; } @@ -698,7 +697,7 @@ static int match_rule(struct udevice *udev, struct udev_rule *rule, dbg("device has no sysfs_device"); goto exit; } - if (match_key(KEY_ID, rule->id, rule->id_operation, parent_device->bus_id)) + if (match_key("ID", rule->id, rule->id_operation, parent_device->bus_id)) goto try_parent; } @@ -706,7 +705,6 @@ static int match_rule(struct udevice *udev, struct udev_rule *rule, if (rule->sysfs_pair_count) { int i; - dbg("check " KEY_SYSFS " pairs"); for (i = 0; i < rule->sysfs_pair_count; i++) { struct key_pair *pair; char value[VALUE_SIZE]; @@ -725,11 +723,11 @@ static int match_rule(struct udevice *udev, struct udev_rule *rule, dbg("removed %zi trailing whitespace chars from '%s'", strlen(value)-len, value); } - dbg("check %i " KEY_SYSFS " keys", rule->sysfs_pair_count); + dbg("check %i SYSFS keys", rule->sysfs_pair_count); if (match_key(pair->name, pair->value, pair->operation, value)) goto try_parent; } - dbg("all %i " KEY_SYSFS " keys matched", rule->sysfs_pair_count); + dbg("all %i SYSFS keys matched", rule->sysfs_pair_count); } /* found matching physical device */ @@ -750,7 +748,7 @@ try_parent: strlcpy(import, rule->import, sizeof(import)); apply_format(udev, import, sizeof(import), class_dev, sysfs_device); - dbg("check for " KEY_IMPORT " import='%s'", import); + dbg("check for IMPORT import='%s'", import); if (rule->import_exec) { dbg("run executable file import='%s'", import); rc = import_program_into_env(udev, import); @@ -759,12 +757,12 @@ try_parent: rc = import_file_into_env(udev, import); } if (rc) { - dbg(KEY_IMPORT " failed"); + dbg("IMPORT failed"); if (rule->import_operation != KEY_OP_NOMATCH) goto exit; } else - dbg(KEY_IMPORT " '%s' imported", rule->import); - dbg(KEY_IMPORT " key is true"); + dbg("IMPORT '%s' imported", rule->import); + dbg("IMPORT key is true"); } /* execute external program */ @@ -774,26 +772,26 @@ try_parent: strlcpy(program, rule->program, sizeof(program)); apply_format(udev, program, sizeof(program), class_dev, sysfs_device); - dbg("check for " KEY_PROGRAM " program='%s", program); + dbg("check for PROGRAM program='%s", program); if (execute_program(program, udev->subsystem, result, sizeof(result), NULL) != 0) { - dbg(KEY_PROGRAM " is not matching"); + dbg("PROGRAM is not matching"); if (rule->program_operation != KEY_OP_NOMATCH) goto exit; } else { - dbg(KEY_PROGRAM " matches"); + dbg("PROGRAM matches"); remove_trailing_char(result, '\n'); replace_untrusted_chars(result); dbg("result is '%s'", result); strlcpy(udev->program_result, result, sizeof(udev->program_result)); - dbg(KEY_PROGRAM " returned successful"); + dbg("PROGRAM returned successful"); if (rule->program_operation == KEY_OP_NOMATCH) goto exit; } - dbg(KEY_PROGRAM " key is true"); + dbg("PROGRAM key is true"); } /* check for matching result of external program */ - if (match_key(KEY_RESULT, rule->result, rule->result_operation, udev->program_result)) + if (match_key("RESULT", rule->result, rule->result_operation, udev->program_result)) goto exit; /* rule matches */ diff --git a/udev_rules.h b/udev_rules.h index 14e40abc2c..fb77509cce 100644 --- a/udev_rules.h +++ b/udev_rules.h @@ -27,33 +27,6 @@ #include "udev.h" #include "list.h" - -#define KEY_KERNEL "KERNEL" -#define KEY_SUBSYSTEM "SUBSYSTEM" -#define KEY_ACTION "ACTION" -#define KEY_DEVPATH "DEVPATH" -#define KEY_BUS "BUS" -#define KEY_ID "ID" -#define KEY_PROGRAM "PROGRAM" -#define KEY_RESULT "RESULT" -#define KEY_DRIVER "DRIVER" -#define KEY_SYSFS "SYSFS" -#define KEY_ENV "ENV" -#define KEY_MODALIAS "MODALIAS" -#define KEY_IMPORT "IMPORT" -#define KEY_NAME "NAME" -#define KEY_SYMLINK "SYMLINK" -#define KEY_OWNER "OWNER" -#define KEY_GROUP "GROUP" -#define KEY_MODE "MODE" -#define KEY_RUN "RUN" -#define KEY_OPTIONS "OPTIONS" - -#define OPTION_LAST_RULE "last_rule" -#define OPTION_IGNORE_DEVICE "ignore_device" -#define OPTION_IGNORE_REMOVE "ignore_remove" -#define OPTION_PARTITIONS "all_partitions" - #define KEY_SYSFS_PAIRS_MAX 5 #define KEY_ENV_PAIRS_MAX 5 diff --git a/udev_rules_parse.c b/udev_rules_parse.c index 4bc00dda5a..cf69783c2d 100644 --- a/udev_rules_parse.c +++ b/udev_rules_parse.c @@ -284,59 +284,59 @@ static int rules_parse(const char *filename) if (retval) break; - if (strcasecmp(key, KEY_KERNEL) == 0) { + if (strcasecmp(key, "KERNEL") == 0) { strlcpy(rule.kernel_name, value, sizeof(rule.kernel_name)); rule.kernel_operation = operation; valid = 1; continue; } - if (strcasecmp(key, KEY_SUBSYSTEM) == 0) { + if (strcasecmp(key, "SUBSYSTEM") == 0) { strlcpy(rule.subsystem, value, sizeof(rule.subsystem)); rule.subsystem_operation = operation; valid = 1; continue; } - if (strcasecmp(key, KEY_ACTION) == 0) { + if (strcasecmp(key, "ACTION") == 0) { strlcpy(rule.action, value, sizeof(rule.action)); rule.action_operation = operation; valid = 1; continue; } - if (strcasecmp(key, KEY_DEVPATH) == 0) { + if (strcasecmp(key, "DEVPATH") == 0) { strlcpy(rule.devpath, value, sizeof(rule.devpath)); rule.devpath_operation = operation; valid = 1; continue; } - if (strcasecmp(key, KEY_BUS) == 0) { + if (strcasecmp(key, "BUS") == 0) { strlcpy(rule.bus, value, sizeof(rule.bus)); rule.bus_operation = operation; valid = 1; continue; } - if (strcasecmp(key, KEY_ID) == 0) { + if (strcasecmp(key, "ID") == 0) { strlcpy(rule.id, value, sizeof(rule.id)); rule.id_operation = operation; valid = 1; continue; } - if (strncasecmp(key, KEY_SYSFS, sizeof(KEY_SYSFS)-1) == 0) { + if (strncasecmp(key, "SYSFS", sizeof("SYSFS")-1) == 0) { struct key_pair *pair; if (rule.sysfs_pair_count >= KEY_SYSFS_PAIRS_MAX) { - err("skip rule, to many " KEY_SYSFS " keys in a single rule"); + err("skip rule, to many SYSFS keys in a single rule"); goto error; } pair = &rule.sysfs_pair[rule.sysfs_pair_count]; - attr = get_key_attribute(key + sizeof(KEY_SYSFS)-1); + attr = get_key_attribute(key + sizeof("SYSFS")-1); if (attr == NULL) { - err("error parsing " KEY_SYSFS " attribute"); + err("error parsing SYSFS attribute"); goto error; } strlcpy(pair->name, attr, sizeof(pair->name)); @@ -347,17 +347,17 @@ static int rules_parse(const char *filename) continue; } - if (strncasecmp(key, KEY_ENV, sizeof(KEY_ENV)-1) == 0) { + if (strncasecmp(key, "ENV", sizeof("ENV")-1) == 0) { struct key_pair *pair; if (rule.env_pair_count >= KEY_ENV_PAIRS_MAX) { - err("skip rule, to many " KEY_ENV " keys in a single rule"); + err("skip rule, to many ENV keys in a single rule"); goto error; } pair = &rule.env_pair[rule.env_pair_count]; - attr = get_key_attribute(key + sizeof(KEY_ENV)-1); + attr = get_key_attribute(key + sizeof("ENV")-1); if (attr == NULL) { - err("error parsing " KEY_ENV " attribute"); + err("error parsing ENV attribute"); continue; } strlcpy(pair->name, attr, sizeof(pair->name)); @@ -368,20 +368,20 @@ static int rules_parse(const char *filename) continue; } - if (strcasecmp(key, KEY_MODALIAS) == 0) { + if (strcasecmp(key, "MODALIAS") == 0) { strlcpy(rule.modalias, value, sizeof(rule.modalias)); rule.modalias_operation = operation; valid = 1; continue; } - if (strncasecmp(key, KEY_IMPORT, sizeof(KEY_IMPORT)-1) == 0) { - attr = get_key_attribute(key + sizeof(KEY_IMPORT)-1); + if (strncasecmp(key, "IMPORT", sizeof("IMPORT")-1) == 0) { + attr = get_key_attribute(key + sizeof("IMPORT")-1); if (attr && strstr(attr, "program")) { - dbg(KEY_IMPORT" will be executed"); + dbg("IMPORT will be executed"); rule.import_exec = 1; } else if (attr && strstr(attr, "file")) { - dbg(KEY_IMPORT" will be included as file"); + dbg("IMPORT will be included as file"); } else { /* figure it out if it is executable */ char file[PATH_SIZE]; @@ -392,9 +392,9 @@ static int rules_parse(const char *filename) pos = strchr(file, ' '); if (pos) pos[0] = '\0'; - dbg(KEY_IMPORT" auto mode for '%s'", file); + dbg("IMPORT auto mode for '%s'", file); if (!lstat(file, &stats) && (stats.st_mode & S_IXUSR)) { - dbg(KEY_IMPORT" is executable, will be executed"); + dbg("IMPORT is executable, will be executed"); rule.import_exec = 1; } } @@ -404,21 +404,21 @@ static int rules_parse(const char *filename) continue; } - if (strcasecmp(key, KEY_DRIVER) == 0) { + if (strcasecmp(key, "DRIVER") == 0) { strlcpy(rule.driver, value, sizeof(rule.driver)); rule.driver_operation = operation; valid = 1; continue; } - if (strcasecmp(key, KEY_RESULT) == 0) { + if (strcasecmp(key, "RESULT") == 0) { strlcpy(rule.result, value, sizeof(rule.result)); rule.result_operation = operation; valid = 1; continue; } - if (strcasecmp(key, KEY_PROGRAM) == 0) { + if (strcasecmp(key, "PROGRAM") == 0) { strlcpy(rule.program, value, sizeof(rule.program)); rule.program_operation = operation; program_given = 1; @@ -426,14 +426,14 @@ static int rules_parse(const char *filename) continue; } - if (strncasecmp(key, KEY_NAME, sizeof(KEY_NAME)-1) == 0) { - attr = get_key_attribute(key + sizeof(KEY_NAME)-1); + if (strncasecmp(key, "NAME", sizeof("NAME")-1) == 0) { + attr = get_key_attribute(key + sizeof("NAME")-1); if (attr != NULL) { - if (strstr(attr, OPTION_PARTITIONS) != NULL) { + if (strstr(attr, "all_partitions") != NULL) { dbg("creation of partition nodes requested"); rule.partitions = DEFAULT_PARTITIONS_COUNT; } - if (strstr(attr, OPTION_IGNORE_REMOVE) != NULL) { + if (strstr(attr, "ignore_remove") != NULL) { dbg("remove event should be ignored"); rule.ignore_remove = 1; } @@ -444,55 +444,55 @@ static int rules_parse(const char *filename) continue; } - if (strcasecmp(key, KEY_SYMLINK) == 0) { + if (strcasecmp(key, "SYMLINK") == 0) { strlcpy(rule.symlink, value, sizeof(rule.symlink)); rule.symlink_operation = operation; valid = 1; continue; } - if (strcasecmp(key, KEY_OWNER) == 0) { + if (strcasecmp(key, "OWNER") == 0) { strlcpy(rule.owner, value, sizeof(rule.owner)); rule.owner_operation = operation; valid = 1; continue; } - if (strcasecmp(key, KEY_GROUP) == 0) { + if (strcasecmp(key, "GROUP") == 0) { strlcpy(rule.group, value, sizeof(rule.group)); rule.group_operation = operation; valid = 1; continue; } - if (strcasecmp(key, KEY_MODE) == 0) { + if (strcasecmp(key, "MODE") == 0) { rule.mode = strtol(value, NULL, 8); rule.mode_operation = operation; valid = 1; continue; } - if (strcasecmp(key, KEY_RUN) == 0) { + if (strcasecmp(key, "RUN") == 0) { strlcpy(rule.run, value, sizeof(rule.run)); rule.run_operation = operation; valid = 1; continue; } - if (strcasecmp(key, KEY_OPTIONS) == 0) { - if (strstr(value, OPTION_LAST_RULE) != NULL) { + if (strcasecmp(key, "OPTIONS") == 0) { + if (strstr(value, "last_rule") != NULL) { dbg("last rule to be applied"); rule.last_rule = 1; } - if (strstr(value, OPTION_IGNORE_DEVICE) != NULL) { + if (strstr(value, "ignore_device") != NULL) { dbg("device should be ignored"); rule.ignore_device = 1; } - if (strstr(value, OPTION_IGNORE_REMOVE) != NULL) { + if (strstr(value, "ignore_remove") != NULL) { dbg("remove event should be ignored"); rule.ignore_remove = 1; } - if (strstr(value, OPTION_PARTITIONS) != NULL) { + if (strstr(value, "all_partitions") != NULL) { dbg("creation of partition nodes requested"); rule.partitions = DEFAULT_PARTITIONS_COUNT; } @@ -509,7 +509,7 @@ static int rules_parse(const char *filename) goto error; if ((rule.result[0] != '\0') && (program_given == 0)) { - info(KEY_RESULT " is only useful when " KEY_PROGRAM " is called in any rule before"); + info("RESULT is only useful when PROGRAM is called in any rule before"); goto error; } |