--- namedev_parse.c.orig 2004-02-17 00:02:53.000000000 +0100 +++ namedev_parse.c 2004-02-17 13:26:38.000000000 +0100 @@ -48,10 +48,35 @@ static int add_config_dev(struct config_ return -ENOMEM; memcpy(tmp_dev, new_dev, sizeof(*tmp_dev)); list_add_tail(&tmp_dev->node, &config_device_list); - //dump_config_dev(tmp_dev); + /*dump_config_dev(tmp_dev);*/ return 0; } +/* Update symlink to a given device */ +static int update_config_dev(struct config_device *new_dev) +{ + struct config_device *dev = NULL; + int len = 0; + + dump_config_dev(new_dev); + list_for_each_entry(dev, &config_device_list, node) { + if (strcmp(dev->name, new_dev->name)) { + continue; + } + len = strlen(dev->symlink); + if ((strlen(dev->symlink) + strlen(new_dev->symlink) + 2) < + sizeof(dev->symlink)) { + strcat(dev->symlink, " "); + strcat(dev->symlink, new_dev->symlink); + //dump_config_dev(dev); + return 0; + } else { + break; + } + } + return -1; /* Do I need a special code here?" */ +} + void dump_config_dev(struct config_device *dev) { /*FIXME dump all sysfs's */ @@ -96,6 +121,7 @@ int namedev_init_rules(void) int program_given = 0; int retval = 0; struct config_device dev; + int update = 0; fd = fopen(udev_rules_filename, "r"); if (fd != NULL) { @@ -194,6 +220,16 @@ int namedev_init_rules(void) if (strcasecmp(temp2, FIELD_SYMLINK) == 0) { strfieldcpy(dev.symlink, temp3); + if (update) { + break; + } else { + continue; + } + } + + if (strcasecmp(temp2, FIELD_UPDATE) == 0) { + update = 1; + strfieldcpy(dev.name, temp3); continue; } @@ -203,8 +239,8 @@ int namedev_init_rules(void) } /* simple plausibility check for given keys */ - if ((dev.sysfs_pair[0].file[0] == '\0') ^ - (dev.sysfs_pair[0].value[0] == '\0')) { + if (!update && ((dev.sysfs_pair[0].file[0] == '\0') ^ + (dev.sysfs_pair[0].value[0] == '\0'))) { dbg("inconsistency in SYSFS_ key"); goto error; } @@ -214,15 +250,33 @@ int namedev_init_rules(void) goto error; } + if (update) { + if ((dev.name[0] == '\0') && + (dev.symlink[0] == '\0')) { + dbg("Updating symlink needs both NAME and SYMLINK"); + goto error; + } + } + dev.config_line = lineno; - retval = add_config_dev(&dev); + if (update) { + retval = update_config_dev(&dev); + // dump_config_dev_list(); + } else { + retval = add_config_dev(&dev); + } if (retval) { - dbg("add_config_dev returned with error %d", retval); + if (update) { + dbg("update_config_dev returned with error %d", retval); + } else { + dbg("add_config_dev returned with error %d", retval); + } continue; error: dbg("%s:%d:%d: parse error, rule skipped", udev_rules_filename, lineno, temp - line); } + update=0; } exit: fclose(fd);