chiark / gitweb /
change parameter order of udev_db_search_name()
authorKay Sievers <kay.sievers@suse.de>
Sat, 27 Aug 2005 13:46:58 +0000 (15:46 +0200)
committerKay Sievers <kay.sievers@suse.de>
Sat, 27 Aug 2005 13:46:58 +0000 (15:46 +0200)
Signed-off-by: Kay Sievers <kay.sievers@suse.de>
udev_db.c
udev_db.h
udev_rules.c
udevinfo.c

index d958c61..5377a3b 100644 (file)
--- a/udev_db.c
+++ b/udev_db.c
@@ -202,7 +202,7 @@ int udev_db_get_device(struct udevice *udev, const char *devpath)
        return 0;
 }
 
-int udev_db_search_name(char *devpath, size_t len, const char *name)
+int udev_db_search_name(const char *name, char *devpath, size_t len)
 {
        DIR *dir;
        char path[PATH_SIZE];
index 61ea5b4..b0bc51a 100644 (file)
--- a/udev_db.h
+++ b/udev_db.h
@@ -27,7 +27,7 @@ extern int udev_db_add_device(struct udevice *dev);
 extern int udev_db_delete_device(struct udevice *dev);
 
 extern int udev_db_get_device(struct udevice *udev, const char *devpath);
-extern int udev_db_search_name(char *devpath, size_t len, const char *name);
+extern int udev_db_search_name(const char *name, char *devpath, size_t len);
 extern int udev_db_get_all_entries(struct list_head *name_list);
 
 #endif /* _UDEV_DB_H_ */
index 6c6aa0f..8db7fd3 100644 (file)
@@ -270,28 +270,31 @@ static int import_parent_into_env(struct udevice *udev, struct sysfs_class_devic
 /* finds the lowest positive N such that <name>N isn't present in the udevdb
  * if <name> doesn't exist, 0 is returned, N otherwise
  */
-static int find_free_number(const char *name)
+static int find_free_number(const char *name, const char *devpath)
 {
-       char devpath[PATH_SIZE];
+       char db_devpath[PATH_SIZE];
        char filename[PATH_SIZE];
        int num = 0;
 
        strlcpy(filename, name, sizeof(filename));
        while (1) {
                dbg("look for existing node '%s'", filename);
-               if (udev_db_search_name(devpath, sizeof(devpath), filename) != 0) {
+               if (udev_db_search_name(filename, db_devpath, sizeof(db_devpath)) != 0) {
                        dbg("free num=%d", num);
-                       return num;
+                       break;
                }
 
                num++;
-               if (num > 1000) {
-                       info("find_free_number gone crazy (num=%d), aborted", num);
-                       return -1;
+               if (num > 100000) {
+                       err("find_free_number aborted at num=%d", num);
+                       num = -1;
+                       break;
                }
                snprintf(filename, sizeof(filename), "%s%d", name, num);
                filename[sizeof(filename)-1] = '\0';
        }
+
+       return num;
 }
 
 static int find_sysfs_attribute(struct sysfs_class_device *class_dev, struct sysfs_device *sysfs_device,
@@ -546,7 +549,7 @@ found:
                        dbg("substitute sysfs value '%s'", temp2);
                        break;
                case SUBST_ENUM:
-                       next_free_number = find_free_number(string);
+                       next_free_number = find_free_number(string, udev->devpath);
                        if (next_free_number > 0) {
                                sprintf(temp2, "%d", next_free_number);
                                strlcat(string, temp2, maxsize);
index 11b0104..b546488 100644 (file)
@@ -321,7 +321,7 @@ int main(int argc, char *argv[], char *envp[])
                        } else
                                pos = name;
 
-                       retval = udev_db_search_name(devpath, sizeof(devpath), pos);
+                       retval = udev_db_search_name(pos, devpath, sizeof(devpath));
                        if (retval != 0) {
                                fprintf(stderr, "no record for '%s' in database\n", pos);
                                goto exit;