X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=namedev_parse.c;h=d5d2181cb68bb427ba34c84f187aff12187e0202;hb=ab2e5bd94631eb3fcc66ec0aaa031d83a2de1604;hp=98e822dfef4bd82c34350179602b6e02d780b741;hpb=ac28b86d631f23b5df74dbeb33e76a2b3f5d88bb;p=elogind.git diff --git a/namedev_parse.c b/namedev_parse.c index 98e822dfe..d5d2181cb 100644 --- a/namedev_parse.c +++ b/namedev_parse.c @@ -3,7 +3,7 @@ * * Userspace devfs * - * Copyright (C) 2003 Greg Kroah-Hartman + * Copyright (C) 2003,2004 Greg Kroah-Hartman * * * This program is free software; you can redistribute it and/or modify it @@ -21,8 +21,10 @@ * */ -/* define this to enable parsing debugging */ +#ifdef DEBUG +/* define this to enable parsing debugging also */ /* #define DEBUG_PARSER */ +#endif #include #include @@ -34,6 +36,7 @@ #include #include "udev.h" +#include "logging.h" #include "namedev.h" static int add_config_dev(struct config_device *new_dev) @@ -49,41 +52,6 @@ static int add_config_dev(struct config_device *new_dev) return 0; } -int get_pair(char **orig_string, char **left, char **right) -{ - char *temp; - char *string = *orig_string; - - if (!string) - return -ENODEV; - - /* eat any whitespace */ - while (isspace(*string) || *string == ',') - ++string; - - /* split based on '=' */ - temp = strsep(&string, "="); - *left = temp; - if (!string) - return -ENODEV; - - /* take the right side and strip off the '"' */ - while (isspace(*string)) - ++string; - if (*string == '"') - ++string; - else - return -ENODEV; - - temp = strsep(&string, "\""); - if (!string || *temp == '\0') - return -ENODEV; - *right = temp; - *orig_string = string; - - return 0; -} - void dump_config_dev(struct config_device *dev) { /*FIXME dump all sysfs's */ @@ -117,6 +85,34 @@ void dump_perm_dev_list(void) dump_perm_dev(dev); } +/* extract possible KEY{attr} or KEY_attr */ +static char *get_key_attribute(char *str) +{ + char *pos; + char *attr; + + attr = strchr(str, '{'); + if (attr != NULL) { + attr++; + pos = strchr(attr, '}'); + if (pos == NULL) { + dbg("missing closing brace for format"); + return NULL; + } + pos[0] = '\0'; + dbg("attribute='%s'", attr); + return attr; + } + + attr = strchr(str, '_'); + if (attr != NULL) { + attr++; + dbg("attribute='%s'", attr); + return attr; + } + + return NULL; +} int namedev_init_rules(void) { @@ -125,6 +121,7 @@ int namedev_init_rules(void) char *temp; char *temp2; char *temp3; + char *attr; FILE *fd; int program_given = 0; int retval = 0; @@ -164,7 +161,7 @@ int namedev_init_rules(void) /* get all known keys */ while (1) { - retval = get_pair(&temp, &temp2, &temp3); + retval = parse_get_pair(&temp, &temp2, &temp3); if (retval) break; @@ -197,8 +194,12 @@ int namedev_init_rules(void) ++pair; } if (pair) { - /* remove prepended 'SYSFS_' */ - strfieldcpy(pair->file, temp2 + sizeof(FIELD_SYSFS)-1); + attr = get_key_attribute(temp2 + sizeof(FIELD_SYSFS)-1); + if (attr == NULL) { + dbg("error parsing " FIELD_SYSFS " attribute"); + continue; + } + strfieldcpy(pair->file, attr); strfieldcpy(pair->value, temp3); } continue; @@ -220,7 +221,13 @@ int namedev_init_rules(void) continue; } - if (strcasecmp(temp2, FIELD_NAME) == 0) { + if (strncasecmp(temp2, FIELD_NAME, sizeof(FIELD_NAME)-1) == 0) { + attr = get_key_attribute(temp2 + sizeof(FIELD_NAME)-1); + if (attr != NULL) + if (strcasecmp(attr, ATTR_PARTITIONS) == 0) { + dbg_parse("creation of partition nodes requested"); + dev.partitions = PARTITIONS_COUNT; + } strfieldcpy(dev.name, temp3); continue; } @@ -230,27 +237,31 @@ int namedev_init_rules(void) continue; } - dbg_parse("unknown type of field '%s'", temp2); + dbg("unknown type of field '%s'", temp2); + dbg("You might be using a rules file in the old format, please fix."); + goto error; } /* simple plausibility check for given keys */ if ((dev.sysfs_pair[0].file[0] == '\0') ^ (dev.sysfs_pair[0].value[0] == '\0')) { - dbg("inconsistency in SYSFS_ key"); + dbg("inconsistency in " FIELD_SYSFS " key"); goto error; } if ((dev.result[0] != '\0') && (program_given == 0)) { - dbg("RESULT is only useful when PROGRAM called in any rule before"); + dbg(FIELD_RESULT " is only useful when " + FIELD_PROGRAM " is called in any rule before"); goto error; } + dev.config_line = lineno; retval = add_config_dev(&dev); if (retval) { dbg("add_config_dev returned with error %d", retval); continue; error: - dbg("%s:%d:%Zd: parse error, rule skipped", + dbg("%s:%d:%d: parse error, rule skipped", udev_rules_filename, lineno, temp - line); } } @@ -318,7 +329,7 @@ int namedev_init_permissions(void) dbg("cannot parse line '%s'", line); continue; } - strncpy(dev.group, temp2, sizeof(dev.owner)); + strncpy(dev.group, temp2, sizeof(dev.group)); if (!temp) { dbg("cannot parse line: %s", line); @@ -339,6 +350,5 @@ int namedev_init_permissions(void) exit: fclose(fd); return retval; -} - +}