chiark / gitweb /
store the imported device information in the udevdb
[elogind.git] / udev_utils.c
index 9e2e152..3ab9e43 100644 (file)
@@ -47,6 +47,7 @@ int udev_init_device(struct udevice *udev, const char* devpath, const char *subs
        memset(udev, 0x00, sizeof(struct udevice));
        INIT_LIST_HEAD(&udev->symlink_list);
        INIT_LIST_HEAD(&udev->run_list);
+       INIT_LIST_HEAD(&udev->env_list);
 
        if (subsystem)
                strlcpy(udev->subsystem, subsystem, sizeof(udev->subsystem));
@@ -112,6 +113,10 @@ void udev_cleanup_device(struct udevice *udev)
                list_del(&name_loop->node);
                free(name_loop);
        }
+       list_for_each_entry_safe(name_loop, temp_loop, &udev->env_list, node) {
+               list_del(&name_loop->node);
+               free(name_loop);
+       }
 }
 
 int string_is_true(const char *str)
@@ -303,10 +308,14 @@ int name_list_add(struct list_head *name_list, const char *name, int sort)
                        dbg("'%s' is already in the list", name);
                        return 0;
                }
-               if (sort && strcmp(loop_name->name, name) > 0)
-                       break;
        }
 
+       if (sort)
+               list_for_each_entry(loop_name, name_list, node) {
+                       if (sort && strcmp(loop_name->name, name) > 0)
+                               break;
+               }
+
        new_name = malloc(sizeof(struct name_entry));
        if (new_name == NULL) {
                dbg("error malloc");
@@ -314,6 +323,35 @@ int name_list_add(struct list_head *name_list, const char *name, int sort)
        }
 
        strlcpy(new_name->name, name, sizeof(new_name->name));
+       dbg("adding '%s'", new_name->name);
+       list_add_tail(&new_name->node, &loop_name->node);
+
+       return 0;
+}
+
+int name_list_key_add(struct list_head *name_list, const char *key, const char *value)
+{
+       struct name_entry *loop_name;
+       struct name_entry *new_name;
+
+       list_for_each_entry(loop_name, name_list, node) {
+               if (strncmp(loop_name->name, key, strlen(key)) == 0) {
+                       dbg("key already present '%s', replace it", loop_name->name);
+                       snprintf(loop_name->name, sizeof(loop_name->name), "%s=%s", key, value);
+                       loop_name->name[sizeof(loop_name->name)-1] = '\0';
+                       return 0;
+               }
+       }
+
+       new_name = malloc(sizeof(struct name_entry));
+       if (new_name == NULL) {
+               dbg("error malloc");
+               return -ENOMEM;
+       }
+
+       snprintf(new_name->name, sizeof(new_name->name), "%s=%s", key, value);
+       new_name->name[sizeof(new_name->name)-1] = '\0';
+       dbg("adding '%s'", new_name->name);
        list_add_tail(&new_name->node, &loop_name->node);
 
        return 0;