chiark / gitweb /
rule_generator: always match netif type in generated rule
[elogind.git] / udev_sysfs.c
index 6e6f16c16fd2266b42b52c33926518a93f30f2b3..e8909f94f1f6166249fbcad8f571d7c0baa2b790 100644 (file)
@@ -155,9 +155,21 @@ struct sysfs_device *sysfs_device_get(const char *devpath)
        int len;
        char *pos;
 
+       /* we handle only these devpathes */
+       if (devpath != NULL &&
+           strncmp(devpath, "/devices/", 9) != 0 &&
+           strncmp(devpath, "/subsystem/", 11) != 0 &&
+           strncmp(devpath, "/module/", 8) != 0 &&
+           strncmp(devpath, "/bus/", 5) != 0 &&
+           strncmp(devpath, "/class/", 7) != 0 &&
+           strncmp(devpath, "/block/", 7) != 0)
+               return NULL;
+
        dbg("open '%s'", devpath);
        strlcpy(devpath_real, devpath, sizeof(devpath_real));
        remove_trailing_chars(devpath_real, '/');
+       if (devpath[0] == '\0' )
+               return NULL;
 
        /* look for device already in cache (we never put an untranslated path in the cache) */
        list_for_each_entry(dev_loop, &dev_list, node) {
@@ -275,14 +287,6 @@ struct sysfs_device *sysfs_device_get_parent(struct sysfs_device *dev)
        if (dev->parent != NULL)
                return dev->parent;
 
-       /* requesting a parent is only valid for these devpathes */
-       if ((strncmp(dev->devpath, "/devices/", 9) != 0) &&
-           (strncmp(dev->devpath, "/subsystem/", 11) != 0) &&
-           (strncmp(dev->devpath, "/bus/", 5) != 0) &&
-           (strncmp(dev->devpath, "/class/", 7) != 0) &&
-           (strncmp(dev->devpath, "/block/", 7) != 0))
-               return NULL;
-
        strlcpy(parent_devpath, dev->devpath, sizeof(parent_devpath));
        dbg("'%s'", parent_devpath);
 
@@ -351,6 +355,8 @@ char *sysfs_attr_get_value(const char *devpath, const char *attr_name)
 
        dbg("open '%s'/'%s'", devpath, attr_name);
        sysfs_len = strlcpy(path_full, sysfs_path, sizeof(path_full));
+       if(sysfs_len >= sizeof(path_full))
+               sysfs_len = sizeof(path_full) - 1;
        path = &path_full[sysfs_len];
        strlcat(path_full, devpath, sizeof(path_full));
        strlcat(path_full, "/", sizeof(path_full));
@@ -409,7 +415,7 @@ char *sysfs_attr_get_value(const char *devpath, const char *attr_name)
        /* read attribute value */
        fd = open(path_full, O_RDONLY);
        if (fd < 0) {
-               dbg("attribute '%s' does not exist", path_full);
+               dbg("attribute '%s' can not be opened", path_full);
                goto out;
        }
        size = read(fd, value, sizeof(value));