summaryrefslogtreecommitdiff
path: root/libudev
diff options
context:
space:
mode:
Diffstat (limited to 'libudev')
-rw-r--r--libudev/libudev-device-private.c4
-rw-r--r--libudev/libudev-device.c18
-rw-r--r--libudev/libudev-enumerate.c22
-rw-r--r--libudev/libudev-list.c23
-rw-r--r--libudev/libudev-monitor.c4
-rw-r--r--libudev/libudev-private.h12
-rw-r--r--libudev/libudev-queue.c4
-rw-r--r--libudev/libudev.c2
8 files changed, 49 insertions, 40 deletions
diff --git a/libudev/libudev-device-private.c b/libudev/libudev-device-private.c
index ee9e297cea..b78b6c9553 100644
--- a/libudev/libudev-device-private.c
+++ b/libudev/libudev-device-private.c
@@ -86,7 +86,7 @@ static bool device_has_info(struct udev_device *udev_device)
if (udev_device_get_devlink_priority(udev_device) != 0)
return true;
udev_list_entry_foreach(list_entry, udev_device_get_properties_list_entry(udev_device))
- if (udev_list_entry_get_flags(list_entry))
+ if (udev_list_entry_get_num(list_entry))
return true;
if (udev_device_get_tags_list_entry(udev_device) != NULL)
return true;
@@ -157,7 +157,7 @@ int udev_device_update_db(struct udev_device *udev_device)
if (udev_device_get_usec_initialized(udev_device) > 0)
fprintf(f, "I:%llu\n", udev_device_get_usec_initialized(udev_device));
udev_list_entry_foreach(list_entry, udev_device_get_properties_list_entry(udev_device)) {
- if (!udev_list_entry_get_flags(list_entry))
+ if (!udev_list_entry_get_num(list_entry))
continue;
fprintf(f, "E:%s=%s\n",
udev_list_entry_get_name(list_entry),
diff --git a/libudev/libudev-device.c b/libudev/libudev-device.c
index 0ef7260de2..ffde21ad57 100644
--- a/libudev/libudev-device.c
+++ b/libudev/libudev-device.c
@@ -103,7 +103,7 @@ struct udev_list_entry *udev_device_add_property(struct udev_device *udev_device
udev_list_entry_delete(list_entry);
return NULL;
}
- return udev_list_entry_add(udev_device->udev, &udev_device->properties_list, key, value, 1, 0);
+ return udev_list_entry_add(udev_device->udev, &udev_device->properties_list, key, value, UDEV_LIST_UNIQUE);
}
static struct udev_list_entry *udev_device_add_property_from_string(struct udev_device *udev_device, const char *property)
@@ -289,7 +289,7 @@ int udev_device_read_db(struct udev_device *udev_device, const char *dbfile)
break;
case 'E':
entry = udev_device_add_property_from_string(udev_device, val);
- udev_list_entry_set_flags(entry, 1);
+ udev_list_entry_set_num(entry, true);
break;
case 'G':
udev_device_add_tag(udev_device, val);
@@ -1216,7 +1216,7 @@ const char *udev_device_get_sysattr_value(struct udev_device *udev_device, const
util_strscpyl(path, sizeof(path), udev_device_get_syspath(udev_device), "/", sysattr, NULL);
if (lstat(path, &statbuf) != 0) {
dbg(udev_device->udev, "no attribute '%s', keep negative entry\n", path);
- udev_list_entry_add(udev_device->udev, &udev_device->sysattr_value_list, sysattr, NULL, 0, 0);
+ udev_list_entry_add(udev_device->udev, &udev_device->sysattr_value_list, sysattr, NULL, 0);
goto out;
}
@@ -1240,7 +1240,7 @@ const char *udev_device_get_sysattr_value(struct udev_device *udev_device, const
if (pos != NULL) {
pos = &pos[1];
dbg(udev_device->udev, "cache '%s' with link value '%s'\n", sysattr, pos);
- list_entry = udev_list_entry_add(udev_device->udev, &udev_device->sysattr_value_list, sysattr, pos, 0, 0);
+ list_entry = udev_list_entry_add(udev_device->udev, &udev_device->sysattr_value_list, sysattr, pos, 0);
val = udev_list_entry_get_value(list_entry);
}
@@ -1272,7 +1272,7 @@ const char *udev_device_get_sysattr_value(struct udev_device *udev_device, const
value[size] = '\0';
util_remove_trailing_chars(value, '\n');
dbg(udev_device->udev, "'%s' has attribute value '%s'\n", path, value);
- list_entry = udev_list_entry_add(udev_device->udev, &udev_device->sysattr_value_list, sysattr, value, 0, 0);
+ list_entry = udev_list_entry_add(udev_device->udev, &udev_device->sysattr_value_list, sysattr, value, 0);
val = udev_list_entry_get_value(list_entry);
out:
return val;
@@ -1311,7 +1311,7 @@ static int udev_device_sysattr_list_read(struct udev_device *udev_device)
continue;
udev_list_entry_add(udev_device->udev, &udev_device->sysattr_list,
- dent->d_name, NULL, 0, 0);
+ dent->d_name, NULL, 0);
num++;
}
@@ -1419,11 +1419,11 @@ int udev_device_add_devlink(struct udev_device *udev_device, const char *devlink
struct udev_list_entry *list_entry;
udev_device->devlinks_uptodate = false;
- list_entry = udev_list_entry_add(udev_device->udev, &udev_device->devlinks_list, devlink, NULL, 1, 0);
+ list_entry = udev_list_entry_add(udev_device->udev, &udev_device->devlinks_list, devlink, NULL, UDEV_LIST_UNIQUE);
if (list_entry == NULL)
return -ENOMEM;
if (unique)
- udev_list_entry_set_flags(list_entry, 1);
+ udev_list_entry_set_num(list_entry, true);
return 0;
}
@@ -1491,7 +1491,7 @@ int udev_device_add_tag(struct udev_device *udev_device, const char *tag)
if (strchr(tag, ':') != NULL || strchr(tag, ' ') != NULL)
return -EINVAL;
udev_device->tags_uptodate = false;
- if (udev_list_entry_add(udev_device->udev, &udev_device->tags_list, tag, NULL, 1, 0) != NULL)
+ if (udev_list_entry_add(udev_device->udev, &udev_device->tags_list, tag, NULL, UDEV_LIST_UNIQUE) != NULL)
return 0;
return -ENOMEM;
}
diff --git a/libudev/libudev-enumerate.c b/libudev/libudev-enumerate.c
index 6870bb6115..018d89cc04 100644
--- a/libudev/libudev-enumerate.c
+++ b/libudev/libudev-enumerate.c
@@ -295,24 +295,24 @@ struct udev_list_entry *udev_enumerate_get_list_entry(struct udev_enumerate *ude
strncmp(entry->syspath, move_later->syspath, move_later_prefix) != 0) {
udev_list_entry_add(udev_enumerate->udev, &udev_enumerate->devices_list,
- move_later->syspath, NULL, 0, 0);
+ move_later->syspath, NULL, 0);
move_later = NULL;
}
udev_list_entry_add(udev_enumerate->udev, &udev_enumerate->devices_list,
- entry->syspath, NULL, 0, 0);
+ entry->syspath, NULL, 0);
}
if (move_later)
udev_list_entry_add(udev_enumerate->udev, &udev_enumerate->devices_list,
- move_later->syspath, NULL, 0, 0);
+ move_later->syspath, NULL, 0);
/* add and cleanup delayed devices from end of list */
for (i = max; i < udev_enumerate->devices_cur; i++) {
struct syspath *entry = &udev_enumerate->devices[i];
udev_list_entry_add(udev_enumerate->udev, &udev_enumerate->devices_list,
- entry->syspath, NULL, 0, 0);
+ entry->syspath, NULL, 0);
free(entry->syspath);
}
udev_enumerate->devices_cur = max;
@@ -336,7 +336,7 @@ int udev_enumerate_add_match_subsystem(struct udev_enumerate *udev_enumerate, co
if (subsystem == NULL)
return 0;
if (udev_list_entry_add(udev_enumerate_get_udev(udev_enumerate),
- &udev_enumerate->subsystem_match_list, subsystem, NULL, 1, 0) == NULL)
+ &udev_enumerate->subsystem_match_list, subsystem, NULL, UDEV_LIST_UNIQUE) == NULL)
return -ENOMEM;
return 0;
}
@@ -355,7 +355,7 @@ int udev_enumerate_add_nomatch_subsystem(struct udev_enumerate *udev_enumerate,
if (subsystem == NULL)
return 0;
if (udev_list_entry_add(udev_enumerate_get_udev(udev_enumerate),
- &udev_enumerate->subsystem_nomatch_list, subsystem, NULL, 1, 0) == NULL)
+ &udev_enumerate->subsystem_nomatch_list, subsystem, NULL, UDEV_LIST_UNIQUE) == NULL)
return -ENOMEM;
return 0;
}
@@ -375,7 +375,7 @@ int udev_enumerate_add_match_sysattr(struct udev_enumerate *udev_enumerate, cons
if (sysattr == NULL)
return 0;
if (udev_list_entry_add(udev_enumerate_get_udev(udev_enumerate),
- &udev_enumerate->sysattr_match_list, sysattr, value, 0, 0) == NULL)
+ &udev_enumerate->sysattr_match_list, sysattr, value, 0) == NULL)
return -ENOMEM;
return 0;
}
@@ -395,7 +395,7 @@ int udev_enumerate_add_nomatch_sysattr(struct udev_enumerate *udev_enumerate, co
if (sysattr == NULL)
return 0;
if (udev_list_entry_add(udev_enumerate_get_udev(udev_enumerate),
- &udev_enumerate->sysattr_nomatch_list, sysattr, value, 0, 0) == NULL)
+ &udev_enumerate->sysattr_nomatch_list, sysattr, value, 0) == NULL)
return -ENOMEM;
return 0;
}
@@ -435,7 +435,7 @@ int udev_enumerate_add_match_property(struct udev_enumerate *udev_enumerate, con
if (property == NULL)
return 0;
if (udev_list_entry_add(udev_enumerate_get_udev(udev_enumerate),
- &udev_enumerate->properties_match_list, property, value, 0, 0) == NULL)
+ &udev_enumerate->properties_match_list, property, value, 0) == NULL)
return -ENOMEM;
return 0;
}
@@ -454,7 +454,7 @@ int udev_enumerate_add_match_tag(struct udev_enumerate *udev_enumerate, const ch
if (tag == NULL)
return 0;
if (udev_list_entry_add(udev_enumerate_get_udev(udev_enumerate),
- &udev_enumerate->tags_match_list, tag, NULL, 1, 0) == NULL)
+ &udev_enumerate->tags_match_list, tag, NULL, UDEV_LIST_UNIQUE) == NULL)
return -ENOMEM;
return 0;
}
@@ -499,7 +499,7 @@ int udev_enumerate_add_match_sysname(struct udev_enumerate *udev_enumerate, cons
if (sysname == NULL)
return 0;
if (udev_list_entry_add(udev_enumerate_get_udev(udev_enumerate),
- &udev_enumerate->sysname_match_list, sysname, NULL, 1, 0) == NULL)
+ &udev_enumerate->sysname_match_list, sysname, NULL, UDEV_LIST_UNIQUE) == NULL)
return -ENOMEM;
return 0;
}
diff --git a/libudev/libudev-list.c b/libudev/libudev-list.c
index b5e96458cc..29453ac251 100644
--- a/libudev/libudev-list.c
+++ b/libudev/libudev-list.c
@@ -38,10 +38,10 @@ struct udev_list_entry {
struct udev_list_node *list;
char *name;
char *value;
- unsigned int flags;
+ int num;
};
-/* list head point to itself if empty */
+/* the list's head points to itself if empty */
void udev_list_init(struct udev_list_node *list)
{
list->next = list;
@@ -114,12 +114,12 @@ void udev_list_entry_insert_before(struct udev_list_entry *new, struct udev_list
struct udev_list_entry *udev_list_entry_add(struct udev *udev, struct udev_list_node *list,
const char *name, const char *value,
- int unique, int sort)
+ unsigned int flags)
{
struct udev_list_entry *entry_loop = NULL;
struct udev_list_entry *entry_new;
- if (unique)
+ if (flags & UDEV_LIST_UNIQUE) {
udev_list_entry_foreach(entry_loop, udev_list_get_entry(list)) {
if (strcmp(entry_loop->name, name) == 0) {
dbg(udev, "'%s' is already in the list\n", name);
@@ -136,12 +136,14 @@ struct udev_list_entry *udev_list_entry_add(struct udev *udev, struct udev_list_
return entry_loop;
}
}
+ }
- if (sort)
+ if (flags & UDEV_LIST_SORT) {
udev_list_entry_foreach(entry_loop, udev_list_get_entry(list)) {
if (strcmp(entry_loop->name, name) > 0)
break;
}
+ }
entry_new = malloc(sizeof(struct udev_list_entry));
if (entry_new == NULL)
@@ -153,6 +155,7 @@ struct udev_list_entry *udev_list_entry_add(struct udev *udev, struct udev_list_
free(entry_new);
return NULL;
}
+
if (value != NULL) {
entry_new->value = strdup(value);
if (entry_new->value == NULL) {
@@ -161,10 +164,12 @@ struct udev_list_entry *udev_list_entry_add(struct udev *udev, struct udev_list_
return NULL;
}
}
+
if (entry_loop != NULL)
udev_list_entry_insert_before(entry_new, entry_loop);
else
udev_list_entry_append(entry_new, list);
+
dbg(udev, "'%s=%s' added\n", entry_new->name, entry_new->value);
return entry_new;
}
@@ -258,16 +263,16 @@ const char *udev_list_entry_get_value(struct udev_list_entry *list_entry)
return list_entry->value;
}
-unsigned int udev_list_entry_get_flags(struct udev_list_entry *list_entry)
+int udev_list_entry_get_num(struct udev_list_entry *list_entry)
{
if (list_entry == NULL)
return -EINVAL;
- return list_entry->flags;
+ return list_entry->num;
}
-void udev_list_entry_set_flags(struct udev_list_entry *list_entry, unsigned int flags)
+void udev_list_entry_set_num(struct udev_list_entry *list_entry, int num)
{
if (list_entry == NULL)
return;
- list_entry->flags = flags;
+ list_entry->num = num;
}
diff --git a/libudev/libudev-monitor.c b/libudev/libudev-monitor.c
index d890b4b142..5917b9e497 100644
--- a/libudev/libudev-monitor.c
+++ b/libudev/libudev-monitor.c
@@ -830,7 +830,7 @@ int udev_monitor_filter_add_match_subsystem_devtype(struct udev_monitor *udev_mo
if (subsystem == NULL)
return -EINVAL;
if (udev_list_entry_add(udev_monitor->udev,
- &udev_monitor->filter_subsystem_list, subsystem, devtype, 0, 0) == NULL)
+ &udev_monitor->filter_subsystem_list, subsystem, devtype, 0) == NULL)
return -ENOMEM;
return 0;
}
@@ -854,7 +854,7 @@ int udev_monitor_filter_add_match_tag(struct udev_monitor *udev_monitor, const c
if (tag == NULL)
return -EINVAL;
if (udev_list_entry_add(udev_monitor->udev,
- &udev_monitor->filter_tag_list, tag, NULL, 0, 0) == NULL)
+ &udev_monitor->filter_tag_list, tag, NULL, 0) == NULL)
return -ENOMEM;
return 0;
}
diff --git a/libudev/libudev-private.h b/libudev/libudev-private.h
index c47bbce2d6..dbe7fd17fc 100644
--- a/libudev/libudev-private.h
+++ b/libudev/libudev-private.h
@@ -157,6 +157,11 @@ const char *udev_ctrl_get_set_env(struct udev_ctrl_msg *ctrl_msg);
int udev_ctrl_get_set_children_max(struct udev_ctrl_msg *ctrl_msg);
/* libudev-list.c */
+enum udev_list_flags {
+ UDEV_LIST_NONE = 0,
+ UDEV_LIST_UNIQUE = 1,
+ UDEV_LIST_SORT = 1 << 1,
+};
struct udev_list_node {
struct udev_list_node *next, *prev;
};
@@ -174,16 +179,15 @@ void udev_list_node_remove(struct udev_list_node *entry);
node != list; \
node = tmp, tmp = (tmp)->next)
struct udev_list_entry *udev_list_entry_add(struct udev *udev, struct udev_list_node *list,
- const char *name, const char *value,
- int unique, int sort);
+ const char *name, const char *value, unsigned int flags);
void udev_list_entry_delete(struct udev_list_entry *entry);
void udev_list_entry_remove(struct udev_list_entry *entry);
void udev_list_entry_insert_before(struct udev_list_entry *new, struct udev_list_entry *entry);
void udev_list_entry_append(struct udev_list_entry *new, struct udev_list_node *list);
void udev_list_cleanup_entries(struct udev *udev, struct udev_list_node *name_list);
struct udev_list_entry *udev_list_get_entry(struct udev_list_node *list);
-unsigned int udev_list_entry_get_flags(struct udev_list_entry *list_entry);
-void udev_list_entry_set_flags(struct udev_list_entry *list_entry, unsigned int flags);
+int udev_list_entry_get_num(struct udev_list_entry *list_entry);
+void udev_list_entry_set_num(struct udev_list_entry *list_entry, int num);
#define udev_list_entry_foreach_safe(entry, tmp, first) \
for (entry = first, tmp = udev_list_entry_get_next(entry); \
entry != NULL; \
diff --git a/libudev/libudev-queue.c b/libudev/libudev-queue.c
index 75c5b2425e..ead05c5184 100644
--- a/libudev/libudev-queue.c
+++ b/libudev/libudev-queue.c
@@ -454,7 +454,7 @@ struct udev_list_entry *udev_queue_get_queued_list_entry(struct udev_queue *udev
break;
if (len > 0) {
- udev_list_entry_add(udev_queue->udev, &udev_queue->queue_list, syspath, seqnum_str, 0, 0);
+ udev_list_entry_add(udev_queue->udev, &udev_queue->queue_list, syspath, seqnum_str, 0);
} else {
udev_list_entry_foreach(list_entry, udev_list_get_entry(&udev_queue->queue_list)) {
if (strcmp(seqnum_str, udev_list_entry_get_value(list_entry)) == 0) {
@@ -508,7 +508,7 @@ struct udev_list_entry *udev_queue_get_failed_list_entry(struct udev_queue *udev
util_strscpyl(filename, sizeof(filename), syspath, "/uevent", NULL);
if (stat(filename, &statbuf) != 0)
continue;
- udev_list_entry_add(udev_queue->udev, &udev_queue->failed_list, syspath, NULL, 0, 0);
+ udev_list_entry_add(udev_queue->udev, &udev_queue->failed_list, syspath, NULL, 0);
}
closedir(dir);
return udev_list_get_entry(&udev_queue->failed_list);
diff --git a/libudev/libudev.c b/libudev/libudev.c
index edc24e2fca..6b5c5e9f84 100644
--- a/libudev/libudev.c
+++ b/libudev/libudev.c
@@ -458,7 +458,7 @@ struct udev_list_entry *udev_add_property(struct udev *udev, const char *key, co
udev_list_entry_delete(list_entry);
return NULL;
}
- return udev_list_entry_add(udev, &udev->properties_list, key, value, 1, 0);
+ return udev_list_entry_add(udev, &udev->properties_list, key, value, UDEV_LIST_UNIQUE);
}
struct udev_list_entry *udev_get_properties_list_entry(struct udev *udev)