chiark / gitweb /
read sysfs attribute also from parent class device
[elogind.git] / udev_rules.c
index 6cbaa781f64e5c8b84df593e54147289ebbb2f6f..d86b8e8599cbb301a0878f7e839ccf688fed6e1f 100644 (file)
@@ -1,12 +1,9 @@
 /*
  * udev_rules.c
  *
- * Userspace devfs
- *
  * Copyright (C) 2003 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
  *     under the terms of the GNU General Public License as published by the
  *     Free Software Foundation version 2 of the License.
 #include "udev_db.h"
 
 
-/* compare string with pattern (supports * ? [0-9] [!A-Z]) */
-static int strcmp_pattern(const char *p, const char *s)
-{
-       if (s[0] == '\0') {
-               while (p[0] == '*')
-                       p++;
-               return (p[0] != '\0');
-       }
-       switch (p[0]) {
-       case '[':
-               {
-                       int not = 0;
-                       p++;
-                       if (p[0] == '!') {
-                               not = 1;
-                               p++;
-                       }
-                       while ((p[0] != '\0') && (p[0] != ']')) {
-                               int match = 0;
-                               if (p[1] == '-') {
-                                       if ((s[0] >= p[0]) && (s[0] <= p[2]))
-                                               match = 1;
-                                       p += 3;
-                               } else {
-                                       match = (p[0] == s[0]);
-                                       p++;
-                               }
-                               if (match ^ not) {
-                                       while ((p[0] != '\0') && (p[0] != ']'))
-                                               p++;
-                                       if (p[0] == ']')
-                                               return strcmp_pattern(p+1, s+1);
-                               }
-                       }
-               }
-               break;
-       case '*':
-               if (strcmp_pattern(p, s+1))
-                       return strcmp_pattern(p+1, s);
-               return 0;
-       case '\0':
-               if (s[0] == '\0') {
-                       return 0;
-               }
-               break;
-       default:
-               if ((p[0] == s[0]) || (p[0] == '?'))
-                       return strcmp_pattern(p+1, s+1);
-               break;
-       }
-       return 1;
-}
-
 /* extract possible {attr} and move str behind it */
 static char *get_format_attribute(char **str)
 {
@@ -351,6 +295,7 @@ static int find_free_number(struct udevice *udev, const char *name)
 static int find_sysfs_attribute(struct sysfs_class_device *class_dev, struct sysfs_device *sysfs_device,
                                const char *name, char *value, size_t len)
 {
+       struct sysfs_class_device *class_dev_parent;
        struct sysfs_attribute *tmpattr;
 
        dbg("look for device attribute '%s'", name);
@@ -359,6 +304,12 @@ static int find_sysfs_attribute(struct sysfs_class_device *class_dev, struct sys
                tmpattr = sysfs_get_classdev_attr(class_dev, name);
                if (tmpattr)
                        goto attr_found;
+               class_dev_parent = sysfs_get_classdev_parent(class_dev);
+               if (class_dev_parent) {
+                       tmpattr = sysfs_get_classdev_attr(class_dev_parent, name);
+                       if (tmpattr)
+                               goto attr_found;
+               }
        }
        if (sysfs_device) {
                dbg("look for devices attribute '%s/%s'", sysfs_device->path, name);