- if (rule->result_operation != KEY_OP_UNSET) {
- dbg("check for " KEY_RESULT " rule->result='%s', udev->program_result='%s'",
- rule->result, udev->program_result);
- if (strcmp_pattern(rule->result, udev->program_result) != 0) {
- dbg(KEY_RESULT " is not matching");
- if (rule->result_operation != KEY_OP_NOMATCH)
- goto exit;
- } else {
- dbg(KEY_RESULT " matches");
- if (rule->result_operation == KEY_OP_NOMATCH)
- goto exit;
+ if (match_key("RESULT", rule, &rule->result, udev->program_result))
+ goto nomatch;
+
+ /* import variables returned from program or or file into environment */
+ if (rule->import.operation != KEY_OP_UNSET) {
+ char import[PATH_SIZE];
+ int rc = -1;
+
+ strlcpy(import, key_val(rule, &rule->import), sizeof(import));
+ udev_rules_apply_format(udev, import, sizeof(import));
+ dbg("check for IMPORT import='%s'", import);
+ if (rule->import_type == IMPORT_PROGRAM) {
+ rc = import_program_into_env(udev, import);
+ } else if (rule->import_type == IMPORT_FILE) {
+ dbg("import file import='%s'", import);
+ rc = import_file_into_env(udev, import);
+ } else if (rule->import_type == IMPORT_PARENT) {
+ dbg("import parent import='%s'", import);
+ rc = import_parent_into_env(udev, import);
+ }
+ if (rc != 0) {
+ dbg("IMPORT failed");
+ if (rule->import.operation != KEY_OP_NOMATCH)
+ goto nomatch;
+ } else
+ dbg("IMPORT '%s' imported", key_val(rule, &rule->import));
+ dbg("IMPORT key is true");
+ }
+
+ /* rule matches, if we have ENV assignments export it */
+ for (i = 0; i < rule->env.count; i++) {
+ struct key_pair *pair = &rule->env.keys[i];
+
+ if (pair->key.operation == KEY_OP_ASSIGN) {
+ char temp_value[NAME_SIZE];
+ const char *key_name = key_pair_name(rule, pair);
+ const char *value = key_val(rule, &pair->key);
+
+ /* make sure we don't write to the same string we possibly read from */
+ strlcpy(temp_value, value, sizeof(temp_value));
+ udev_rules_apply_format(udev, temp_value, NAME_SIZE);
+
+ if (temp_value[0] == '\0') {
+ name_list_key_remove(&udev->env_list, key_name);
+ unsetenv(key_name);
+ info("unset ENV '%s'", key_name);
+ } else {
+ char *key_value = name_list_key_add(&udev->env_list, key_name, temp_value);
+
+ if (key_value == NULL)
+ break;
+ putenv(key_value);
+ info("set ENV '%s'", key_value);
+ }