summaryrefslogtreecommitdiff
path: root/udev_utils.c
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@suse.de>2005-06-26 18:55:24 +0200
committerKay Sievers <kay.sievers@suse.de>2005-06-26 18:55:24 +0200
commitb8476286d62c82a1a0bd8de318aa3f7d835222a0 (patch)
tree37d3071c2767f819440083e34c5e68efde584b60 /udev_utils.c
parent208f6aba21199ff4f93002eeb948d564f76843e6 (diff)
store the imported device information in the udevdb
Any program can query with udevinfo for persistent device attributes evaluated on device discovery now. Signed-off-by: Kay Sievers <kay.sievers@suse.de>
Diffstat (limited to 'udev_utils.c')
-rw-r--r--udev_utils.c42
1 files changed, 40 insertions, 2 deletions
diff --git a/udev_utils.c b/udev_utils.c
index 9e2e152763..3ab9e43348 100644
--- a/udev_utils.c
+++ b/udev_utils.c
@@ -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;