strlcpy(program, key_val(rule, &rule->program), sizeof(program));
udev_rules_apply_format(udev, program, sizeof(program));
- if (run_program(program, udev->dev->subsystem, result, sizeof(result), NULL, (udev_log_priority >= LOG_INFO)) != 0) {
+ if (run_program(program, udev->dev->subsystem, result, sizeof(result),
+ NULL, (udev_log_priority >= LOG_INFO)) != 0) {
dbg("PROGRAM is false");
udev->program_result[0] = '\0';
if (rule->program.operation != KEY_OP_NOMATCH)
dbg("PROGRAM matches");
remove_trailing_chars(result, '\n');
- count = replace_chars(result, ALLOWED_CHARS_INPUT);
- if (count)
- info("%i character(s) replaced" , count);
+ if (rule->string_escape == ESCAPE_UNSET ||
+ rule->string_escape == ESCAPE_REPLACE) {
+ count = replace_chars(result, ALLOWED_CHARS_INPUT);
+ if (count > 0)
+ info("%i character(s) replaced" , count);
+ }
dbg("result is '%s'", result);
strlcpy(udev->program_result, result, sizeof(udev->program_result));
dbg("PROGRAM returned successful");
/* allow multiple symlinks separated by spaces */
strlcpy(temp, key_val(rule, &rule->symlink), sizeof(temp));
udev_rules_apply_format(udev, temp, sizeof(temp));
- count = replace_chars(temp, ALLOWED_CHARS_FILE " ");
- if (count)
- info("%i character(s) replaced" , count);
+ if (rule->string_escape == ESCAPE_UNSET ||
+ rule->string_escape == ESCAPE_REPLACE) {
+ count = replace_chars(temp, ALLOWED_CHARS_FILE " ");
+ if (count > 0)
+ info("%i character(s) replaced" , count);
+ }
dbg("rule applied, added symlink(s) '%s'", temp);
pos = temp;
while (isspace(pos[0]))
name_set = 1;
strlcpy(udev->name, key_val(rule, &rule->name), sizeof(udev->name));
udev_rules_apply_format(udev, udev->name, sizeof(udev->name));
- count = replace_chars(udev->name, ALLOWED_CHARS_FILE);
- if (count)
- info("%i character(s) replaced", count);
+ if (rule->string_escape == ESCAPE_UNSET ||
+ rule->string_escape == ESCAPE_REPLACE) {
+ count = replace_chars(udev->name, ALLOWED_CHARS_FILE);
+ if (count > 0)
+ info("%i character(s) replaced", count);
+ }
info("rule applied, '%s' becomes '%s'", udev->dev->kernel, udev->name);
if (strcmp(udev->dev->subsystem, "net") != 0)
static int add_to_rules(struct udev_rules *rules, char *line, const char *filename, unsigned int lineno)
{
+ char buf[sizeof(struct udev_rule) + LINE_SIZE];
struct udev_rule *rule;
size_t rule_size;
int valid;
int physdev = 0;
int retval;
- /* get all the keys */
- rule = calloc(1, sizeof (struct udev_rule) + LINE_SIZE);
- if (!rule) {
- err("malloc failed");
- return -1;
- }
+ memset(buf, 0x00, sizeof(buf));
+ rule = (struct udev_rule *) buf;
linepos = line;
valid = 0;
+ /* get all the keys */
while (1) {
char *key;
char *value;
rule->link_priority = atoi(&pos[strlen("link_priority=")]);
info("link priority=%i", rule->link_priority);
}
+ pos = strstr(value, "string_escape=");
+ if (pos != NULL) {
+ pos = &pos[strlen("string_escape=")];
+ if (strncmp(pos, "none", strlen("none")) == 0)
+ rule->string_escape = ESCAPE_NONE;
+ else if (strncmp(pos, "replace", strlen("replace")) == 0)
+ rule->string_escape = ESCAPE_REPLACE;
+ }
if (strstr(value, "all_partitions") != NULL) {
dbg("creation of partition nodes requested");
rule->partitions = DEFAULT_PARTITIONS_COUNT;
memcpy(rules->buf + rules->bufsize, rule, rule_size);
rules->bufsize += rule_size;
exit:
- free(rule);
return 0;
invalid:
- free(rule);
err("invalid rule '%s:%u'", filename, lineno);
return -1;
}