chiark / gitweb /
[PATCH] fix udev-test/udev-test.pl to work with again
[elogind.git] / namedev_parse.c
index 4bb1a97ce9eb05bc3b8455f33f46b18e41a48b5d..5b8c5ab2d6989a32d8648b6ce048128116d8f144 100644 (file)
@@ -36,7 +36,7 @@
 #include <errno.h>
 
 #include "udev.h"
-#include "udev_lib.h"
+#include "udev_utils.h"
 #include "logging.h"
 #include "namedev.h"
 
@@ -79,12 +79,19 @@ static int add_perm_dev(struct perm_device *new_dev)
        struct perm_device *dev;
        struct perm_device *tmp_dev;
 
-       /* update the values if we already have the device */
+       /* if we already have that entry, just update the values */
        list_for_each_entry(dev, &perm_device_list, node) {
                if (strcmp(new_dev->name, dev->name) != 0)
                        continue;
 
-               set_empty_perms(dev, new_dev->mode, new_dev->owner, new_dev->group);
+               /* don't overwrite values from earlier entries */
+               if (dev->mode == 0000)
+                       dev->mode = new_dev->mode;
+               if (dev->owner[0] == '\0')
+                       strfieldcpy(dev->owner, new_dev->owner);
+               if (dev->owner[0] == '\0')
+                       strfieldcpy(dev->group, new_dev->group);
+
                return 0;
        }
 
@@ -95,7 +102,8 @@ static int add_perm_dev(struct perm_device *new_dev)
 
        memcpy(tmp_dev, new_dev, sizeof(*tmp_dev));
        list_add_tail(&tmp_dev->node, &perm_device_list);
-       //dump_perm_dev(tmp_dev);
+       /* dump_perm_dev(tmp_dev); */
+
        return 0;
 }
 
@@ -113,7 +121,7 @@ void dump_perm_dev_list(void)
                dump_perm_dev(dev);
 }
 
-/* extract possible KEY{attr} or KEY_attr */
+/* extract possible KEY{attr} */
 static char *get_key_attribute(char *str)
 {
        char *pos;
@@ -132,17 +140,10 @@ static char *get_key_attribute(char *str)
                return attr;
        }
 
-       attr = strchr(str, '_');
-       if (attr != NULL) {
-               attr++;
-               dbg("attribute='%s'", attr);
-               return attr;
-       }
-
        return NULL;
 }
 
-static int namedev_parse_rules(char *filename)
+static int namedev_parse_rules(const char *filename, void *data)
 {
        char line[LINE_SIZE];
        char *bufline;
@@ -182,15 +183,13 @@ static int namedev_parse_rules(char *filename)
                        continue;
                }
 
-               /* empty line? */
-               if (bufline[0] == '\0' || bufline[0] == '\n')
-                       continue;
-
                /* eat the whitespace */
-               while (isspace(bufline[0])) {
+               while ((count > 0) && isspace(bufline[0])) {
                        bufline++;
                        count--;
                }
+               if (count == 0)
+                       continue;
 
                /* see if this is a comment */
                if (bufline[0] == COMMENT_CHARACTER)
@@ -260,6 +259,18 @@ static int namedev_parse_rules(char *filename)
                                continue;
                        }
 
+                       if (strcasecmp(temp2, FIELD_SUBSYSTEM) == 0) {
+                               strfieldcpy(dev.subsystem, temp3);
+                               valid = 1;
+                               continue;
+                       }
+
+                       if (strcasecmp(temp2, FIELD_DRIVER) == 0) {
+                               strfieldcpy(dev.driver, temp3);
+                               valid = 1;
+                               continue;
+                       }
+
                        if (strcasecmp(temp2, FIELD_PROGRAM) == 0) {
                                program_given = 1;
                                strfieldcpy(dev.program, temp3);
@@ -275,10 +286,16 @@ static int namedev_parse_rules(char *filename)
 
                        if (strncasecmp(temp2, FIELD_NAME, sizeof(FIELD_NAME)-1) == 0) {
                                attr = get_key_attribute(temp2 + sizeof(FIELD_NAME)-1);
-                               if (attr != NULL && strcasecmp(attr, ATTR_PARTITIONS) == 0) {
+                               if (attr != NULL) {
+                                       if (strstr(attr, ATTR_PARTITIONS) != NULL) {
                                                dbg_parse("creation of partition nodes requested");
                                                dev.partitions = PARTITIONS_COUNT;
                                        }
+                                       if (strstr(attr, ATTR_IGNORE_REMOVE) != NULL) {
+                                               dbg_parse("remove event should be ignored");
+                                               dev.ignore_remove = 1;
+                                       }
+                               }
                                strfieldcpy(dev.name, temp3);
                                valid = 1;
                                continue;
@@ -345,7 +362,7 @@ error:
        return retval;
 }
 
-static int namedev_parse_permissions(char *filename)
+static int namedev_parse_permissions(const char *filename, void *data)
 {
        char line[LINE_SIZE];
        char *bufline;
@@ -381,15 +398,13 @@ static int namedev_parse_permissions(char *filename)
                        continue;
                }
 
-               /* empty line? */
-               if (bufline[0] == '\0' || bufline[0] == '\n')
-                       continue;
-
                /* eat the whitespace */
-               while (isspace(bufline[0])) {
+               while ((count > 0) && isspace(bufline[0])) {
                        bufline++;
                        count--;
                }
+               if (count == 0)
+                       continue;
 
                /* see if this is a comment */
                if (bufline[0] == COMMENT_CHARACTER)
@@ -445,26 +460,26 @@ exit:
        return retval;
 }
 
-int namedev_init_rules()
+int namedev_init_rules(void)
 {
        struct stat stats;
 
        stat(udev_rules_filename, &stats);
        if ((stats.st_mode & S_IFMT) != S_IFDIR)
-               return namedev_parse_rules(udev_rules_filename);
+               return namedev_parse_rules(udev_rules_filename, NULL);
        else
-               return call_foreach_file(namedev_parse_rules,
-                                        udev_rules_filename, RULEFILE_SUFFIX);
+               return call_foreach_file(namedev_parse_rules, udev_rules_filename,
+                                        RULEFILE_SUFFIX, NULL);
 }
 
-int namedev_init_permissions()
+int namedev_init_permissions(void)
 {
        struct stat stats;
 
        stat(udev_permissions_filename, &stats);
        if ((stats.st_mode & S_IFMT) != S_IFDIR)
-               return namedev_parse_permissions(udev_permissions_filename);
+               return namedev_parse_permissions(udev_permissions_filename, NULL);
        else
-               return call_foreach_file(namedev_parse_permissions,
-                                        udev_permissions_filename, PERMFILE_SUFFIX);
+               return call_foreach_file(namedev_parse_permissions, udev_permissions_filename,
+                                        PERMFILE_SUFFIX, NULL);
 }