linepos = line;
if (get_key(&linepos, &variable, &value) == 0) {
dbg("import '%s=%s'", variable, value);
- name_list_key_add(&udev->env_list, variable, value);
+
+ /* handle device, renamed by external tool, returning new path */
+ if (strcmp(variable, "DEVPATH") == 0) {
+ info("updating devpath from '%s' to '%s'", udev->dev->devpath, value);
+ sysfs_device_set_values(udev->dev, value, NULL, NULL);
+ } else
+ name_list_key_add(&udev->env_list, variable, value);
setenv(variable, value, 1);
}
}
goto found;
}
}
+ head[0] = '$';
+ err("unknown format variable '%s'", head);
} else if (head[0] == '%') {
/* substitute format char */
if (head[1] == '\0')
goto found;
}
}
+ head[0] = '%';
+ err("unknown format char '%c'", tail[0]);
}
head++;
}
break;
}
/* possibly truncate to format-char specified length */
- if (len != -1) {
+ if (len >= 0 && len < (int)strlen(head)) {
head[len] = '\0';
dbg("truncate to %i chars, subtitution string becomes '%s'", len, head);
}
if (pair->key.operation == KEY_OP_ASSIGN) {
const char *key_name = key_pair_name(rule, pair);
- const char *key_value = key_val(rule, &pair->key);
char attr[PATH_SIZE];
+ char value[NAME_SIZE];
FILE *f;
strlcpy(attr, sysfs_path, sizeof(attr));
strlcat(attr, udev->dev->devpath, sizeof(attr));
strlcat(attr, "/", sizeof(attr));
strlcat(attr, key_name, sizeof(attr));
- dbg("write '%s' to '%s'", key_value, attr);
+ strlcpy(value, key_val(rule, &pair->key), sizeof(value));
+ udev_rules_apply_format(udev, value, sizeof(value));
+ info("writing '%s' to sysfs file '%s'", value, attr);
f = fopen(attr, "w");
if (f != NULL) {
- if (fprintf(f, "%s\n", key_value) <= 0)
+ if (fprintf(f, "%s", value) <= 0)
err("error writing ATTR{%s}: %s", attr, strerror(errno));
fclose(f);
} else