chiark / gitweb /
move rule matches to function
[elogind.git] / udev_rules_parse.c
index 36bf97177db4172be9f648f18d1c36195a0a6d5e..4bc00dda5a80cab4b7838e99a6d3a2d0ffee1825 100644 (file)
@@ -87,12 +87,12 @@ static int add_rule_to_list(struct udev_rule *rule)
 
        dbg("name='%s', symlink='%s', bus='%s', id='%s', "
            "sysfs_file[0]='%s', sysfs_value[0]='%s', "
-           "kernel='%s', program='%s', result='%s', "
+           "kernel_name='%s', program='%s', result='%s', "
            "owner='%s', group='%s', mode=%#o, "
            "all_partions=%u, ignore_remove=%u, ignore_device=%u, last_rule=%u",
            rule->name, rule->symlink, rule->bus, rule->id,
            rule->sysfs_pair[0].name, rule->sysfs_pair[0].value,
-           rule->kernel, rule->program, rule->result, rule->owner, rule->group, rule->mode,
+           rule->kernel_name, rule->program, rule->result, rule->owner, rule->group, rule->mode,
            rule->partitions, rule->ignore_remove, rule->ignore_device, rule->last_rule);
 
        return 0;
@@ -285,7 +285,7 @@ static int rules_parse(const char *filename)
                                break;
 
                        if (strcasecmp(key, KEY_KERNEL) == 0) {
-                               strlcpy(rule.kernel, value, sizeof(rule.kernel));
+                               strlcpy(rule.kernel_name, value, sizeof(rule.kernel_name));
                                rule.kernel_operation = operation;
                                valid = 1;
                                continue;
@@ -375,6 +375,35 @@ static int rules_parse(const char *filename)
                                continue;
                        }
 
+                       if (strncasecmp(key, KEY_IMPORT, sizeof(KEY_IMPORT)-1) == 0) {
+                               attr = get_key_attribute(key + sizeof(KEY_IMPORT)-1);
+                               if (attr && strstr(attr, "program")) {
+                                       dbg(KEY_IMPORT" will be executed");
+                                       rule.import_exec = 1;
+                               } else if (attr && strstr(attr, "file")) {
+                                       dbg(KEY_IMPORT" will be included as file");
+                               } else {
+                                       /* figure it out if it is executable */
+                                       char file[PATH_SIZE];
+                                       char *pos;
+                                       struct stat stats;
+
+                                       strlcpy(file, value, sizeof(file));
+                                       pos = strchr(file, ' ');
+                                       if (pos)
+                                               pos[0] = '\0';
+                                       dbg(KEY_IMPORT" auto mode for '%s'", file);
+                                       if (!lstat(file, &stats) && (stats.st_mode & S_IXUSR)) {
+                                                       dbg(KEY_IMPORT" is executable, will be executed");
+                                                       rule.import_exec = 1;
+                                       }
+                               }
+                               strlcpy(rule.import, value, sizeof(rule.import));
+                               rule.import_operation = operation;
+                               valid = 1;
+                               continue;
+                       }
+
                        if (strcasecmp(key, KEY_DRIVER) == 0) {
                                strlcpy(rule.driver, value, sizeof(rule.driver));
                                rule.driver_operation = operation;
@@ -404,7 +433,6 @@ static int rules_parse(const char *filename)
                                                dbg("creation of partition nodes requested");
                                                rule.partitions = DEFAULT_PARTITIONS_COUNT;
                                        }
-                                       /* FIXME: remove old style option and make OPTIONS= mandatory */
                                        if (strstr(attr, OPTION_IGNORE_REMOVE) != NULL) {
                                                dbg("remove event should be ignored");
                                                rule.ignore_remove = 1;