chiark / gitweb /
[PATCH] clean up match_place()
[elogind.git] / namedev_parse.c
index 7190cdd1a8702a538f5f454d96e3ca84a00f7b6f..981daa7b3b1d3e5e6a173c2e75e8b3d308d37ee3 100644 (file)
@@ -4,6 +4,7 @@
  * Userspace devfs
  *
  * Copyright (C) 2003,2004 Greg Kroah-Hartman <greg@kroah.com>
+ * Copyright (C) 2003-2005 Kay Sievers <kay.sievers@vrfy.org>
  *
  *
  *     This program is free software; you can redistribute it and/or modify it
@@ -126,14 +127,15 @@ static int namedev_parse(const char *filename, void *data)
        cur = 0;
        lineno = 0;
        while (cur < bufsize) {
+               unsigned int i, j;
+
                count = buf_get_line(buf, bufsize, cur);
                bufline = &buf[cur];
                cur += count+1;
                lineno++;
 
                if (count >= LINE_SIZE) {
-                       info("line too long, rule skipped %s, line %d",
-                            filename, lineno);
+                       info("line too long, rule skipped %s, line %d", filename, lineno);
                        continue;
                }
 
@@ -149,8 +151,14 @@ static int namedev_parse(const char *filename, void *data)
                if (bufline[0] == COMMENT_CHARACTER)
                        continue;
 
-               strncpy(line, bufline, count);
-               line[count] = '\0';
+               /* skip backslash and newline from multi line rules */
+               for (i = j = 0; i < count; i++) {
+                       if (bufline[i] == '\\' || bufline[i] == '\n')
+                               continue;
+
+                       line[j++] = bufline[i];
+               }
+               line[j] = '\0';
                dbg_parse("read '%s'", line);
 
                /* get all known keys */
@@ -240,10 +248,11 @@ static int namedev_parse(const char *filename, void *data)
 
                        if (strncasecmp(temp2, FIELD_NAME, sizeof(FIELD_NAME)-1) == 0) {
                                attr = get_key_attribute(temp2 + sizeof(FIELD_NAME)-1);
+                               /* FIXME: remove old style options and make OPTIONS= mandatory */
                                if (attr != NULL) {
                                        if (strstr(attr, ATTR_PARTITIONS) != NULL) {
                                                dbg_parse("creation of partition nodes requested");
-                                               dev.partitions = PARTITIONS_COUNT;
+                                               dev.partitions = DEFAULT_PARTITIONS_COUNT;
                                        }
                                        if (strstr(attr, ATTR_IGNORE_REMOVE) != NULL) {
                                                dbg_parse("remove event should be ignored");
@@ -279,6 +288,23 @@ static int namedev_parse(const char *filename, void *data)
                                continue;
                        }
 
+                       if (strcasecmp(temp2, FIELD_OPTIONS) == 0) {
+                               if (strstr(temp3, ATTR_IGNORE_DEVICE) != NULL) {
+                                       dbg_parse("device should be ignored");
+                                       dev.ignore_device = 1;
+                               }
+                               if (strstr(temp3, ATTR_IGNORE_REMOVE) != NULL) {
+                                       dbg_parse("remove event should be ignored");
+                                       dev.ignore_remove = 1;
+                               }
+                               if (strstr(temp3, ATTR_PARTITIONS) != NULL) {
+                                       dbg_parse("creation of partition nodes requested");
+                                       dev.partitions = DEFAULT_PARTITIONS_COUNT;
+                               }
+                               valid = 1;
+                               continue;
+                       }
+
                        dbg("unknown type of field '%s'", temp2);
                        goto error;
                }
@@ -331,3 +357,14 @@ int namedev_init(void)
 
        return retval;
 }
+
+void namedev_close(void)
+{
+       struct config_device *dev;
+
+       list_for_each_entry(dev, &config_device_list, node) {
+               list_del(&dev->node);
+               free(dev);
+       }
+}
+