# libudev
# ------------------------------------------------------------------------------
LIBUDEV_CURRENT=11
-LIBUDEV_REVISION=2
+LIBUDEV_REVISION=3
LIBUDEV_AGE=11
SUBDIRS += libudev/docs
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;
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),
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)
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);
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;
}
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);
}
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;
continue;
udev_list_entry_add(udev_device->udev, &udev_device->sysattr_list,
- dent->d_name, NULL, 0, 0);
+ dent->d_name, NULL, 0);
num++;
}
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;
}
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;
}
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;
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
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);
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)
free(entry_new);
return NULL;
}
+
if (value != NULL) {
entry_new->value = strdup(value);
if (entry_new->value == NULL) {
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;
}
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;
}
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;
}
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;
}
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;
};
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; \
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) {
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);
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)
udev_event_apply_format(event, cmd, program, sizeof(program));
envp = udev_device_get_properties_envp(event->dev);
if (udev_event_spawn(event, program, envp, sigmask, NULL, 0) < 0) {
- if (udev_list_entry_get_flags(list_entry))
+ if (udev_list_entry_get_num(list_entry))
err = -1;
}
}
/* create/update symlinks, add symlinks to name index */
udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(dev)) {
- if (udev_list_entry_get_flags(list_entry))
+ if (udev_list_entry_get_num(list_entry))
/* simple unmanaged link name */
node_symlink(udev, udev_device_get_devnode(dev), udev_list_entry_get_name(list_entry));
else
entry = udev_device_add_property(dev, key, val);
/* store in db, skip private keys */
if (key[0] != '.')
- udev_list_entry_set_flags(entry, 1);
+ udev_list_entry_set_num(entry, true);
}
return 0;
}
entry = udev_device_add_property(dev, key, val);
/* store in db, skip private keys */
if (key[0] != '.')
- udev_list_entry_set_flags(entry, 1);
+ udev_list_entry_set_num(entry, true);
}
}
return 0;
* identical basenames from different directories overwrite each other
* entries are sorted after basename
*/
- udev_list_entry_add(udev, file_list, dent->d_name, filename, 1, 1);
+ udev_list_entry_add(udev, file_list, dent->d_name, filename, UDEV_LIST_UNIQUE|UDEV_LIST_SORT);
}
closedir(dir);
filename_off = add_string(rules, filename);
/* the offset in the rule is limited to unsigned short */
if (filename_off < USHRT_MAX)
- udev_list_entry_set_flags(file_loop, filename_off);
+ udev_list_entry_set_num(file_loop, filename_off);
}
/* parse all rules files */
udev_list_entry_foreach(file_loop, udev_list_get_entry(&file_list)) {
const char *filename = udev_list_entry_get_value(file_loop);
- unsigned int filename_off = udev_list_entry_get_flags(file_loop);
+ unsigned int filename_off = udev_list_entry_get_num(file_loop);
struct stat st;
if (stat(filename, &st) != 0) {
struct udev_list_entry *entry;
entry = udev_device_add_property(event->dev, key, value);
- udev_list_entry_set_flags(entry, 1);
+ udev_list_entry_set_num(entry, true);
} else {
if (cur->key.op != OP_NOMATCH)
goto nomatch;
if (pos[0] == '\0' || isspace(pos[0])) {
/* we import simple flags as 'FLAG=1' */
entry = udev_device_add_property(event->dev, key, "1");
- udev_list_entry_set_flags(entry, 1);
+ udev_list_entry_set_num(entry, true);
imported = true;
} else if (pos[0] == '=') {
const char *value;
pos++;
pos[0] = '\0';
entry = udev_device_add_property(event->dev, key, value);
- udev_list_entry_set_flags(entry, 1);
+ udev_list_entry_set_num(entry, true);
imported = true;
}
}
entry = udev_device_add_property(event->dev, name, temp_value);
/* store in db, skip private keys */
if (name[0] != '.')
- udev_list_entry_set_flags(entry, 1);
+ udev_list_entry_set_num(entry, true);
} else {
udev_device_add_property(event->dev, name, NULL);
}
&rules->buf[rule->rule.filename_off],
rule->rule.filename_line);
list_entry = udev_list_entry_add(event->udev, &event->run_list,
- &rules->buf[cur->key.value_off], NULL, 1, 0);
+ &rules->buf[cur->key.value_off], NULL, UDEV_LIST_UNIQUE);
if (cur->key.fail_on_error)
- udev_list_entry_set_flags(list_entry, 1);
+ udev_list_entry_set_num(list_entry, true);
break;
}
case TK_A_GOTO:
devtype[0] = '\0';
devtype++;
}
- udev_list_entry_add(udev, &subsystem_match_list, subsys, devtype, 0, 0);
+ udev_list_entry_add(udev, &subsystem_match_list, subsys, devtype, 0);
break;
}
case 't':
- udev_list_entry_add(udev, &tag_match_list, optarg, NULL, 0, 0);
+ udev_list_entry_add(udev, &tag_match_list, optarg, NULL, 0);
break;
case 'h':
printf("Usage: udevadm monitor [--property] [--kernel] [--udev] [--help]\n"