udevd: use list.h instead of udev_list_node

This commit is contained in:
Simon Peeters 2016-11-06 16:09:32 +01:00 committed by Zbigniew Jędrzejewski-Szmek
parent 8a9b3a23fd
commit 40a5771658
2 changed files with 20 additions and 27 deletions

View File

@ -183,3 +183,6 @@
for ((i) = (p)->name##_next ? (p)->name##_next : (head); \
(i) != (p); \
(i) = (i)->name##_next ? (i)->name##_next : (head))
#define LIST_IS_EMPTY(head) \
(!(head))

View File

@ -54,6 +54,7 @@
#include "fs-util.h"
#include "hashmap.h"
#include "io-util.h"
#include "list.h"
#include "netlink-util.h"
#include "parse-util.h"
#include "proc-cmdline.h"
@ -79,7 +80,7 @@ typedef struct Manager {
struct udev *udev;
sd_event *event;
Hashmap *workers;
struct udev_list_node events;
LIST_HEAD(struct event, events);
const char *cgroup;
pid_t pid; /* the process that originally allocated the manager object */
@ -109,7 +110,7 @@ enum event_state {
};
struct event {
struct udev_list_node node;
LIST_FIELDS(struct event, event);
Manager *manager;
struct udev *udev;
struct udev_device *dev;
@ -128,10 +129,6 @@ struct event {
sd_event_source *timeout;
};
static inline struct event *node_to_event(struct udev_list_node *node) {
return container_of(node, struct event, node);
}
static void event_queue_cleanup(Manager *manager, enum event_state type);
enum worker_state {
@ -160,8 +157,9 @@ static void event_free(struct event *event) {
if (!event)
return;
assert(event->manager);
udev_list_node_remove(&event->node);
LIST_REMOVE(event, event->manager->events, event);
udev_device_unref(event->dev);
udev_device_unref(event->dev_kernel);
@ -171,9 +169,7 @@ static void event_free(struct event *event) {
if (event->worker)
event->worker->event = NULL;
assert(event->manager);
if (udev_list_node_is_empty(&event->manager->events)) {
if (LIST_IS_EMPTY(event->manager->events)) {
/* only clean up the queue from the process that created it */
if (event->manager->pid == getpid_cached()) {
r = unlink("/run/udev/queue");
@ -620,13 +616,13 @@ static int event_queue_insert(Manager *manager, struct udev_device *dev) {
event->state = EVENT_QUEUED;
if (udev_list_node_is_empty(&manager->events)) {
if (LIST_IS_EMPTY(manager->events)) {
r = touch("/run/udev/queue");
if (r < 0)
log_warning_errno(r, "could not touch /run/udev/queue: %m");
}
udev_list_node_append(&event->node, &manager->events);
LIST_APPEND(event, manager->events, event);
return 0;
}
@ -648,13 +644,11 @@ static void manager_kill_workers(Manager *manager) {
/* lookup event for identical, parent, child device */
static bool is_devpath_busy(Manager *manager, struct event *event) {
struct udev_list_node *loop;
struct event *loop_event;
size_t common;
/* check if queue contains events we depend on */
udev_list_node_foreach(loop, &manager->events) {
struct event *loop_event = node_to_event(loop);
LIST_FOREACH(event, loop_event, manager->events) {
/* we already found a later event, earlier can not block us, no need to check again */
if (loop_event->seqnum < event->delaying_seqnum)
continue;
@ -783,12 +777,12 @@ static void manager_reload(Manager *manager) {
}
static void event_queue_start(Manager *manager) {
struct udev_list_node *loop;
struct event *event;
usec_t usec;
assert(manager);
if (udev_list_node_is_empty(&manager->events) ||
if (LIST_IS_EMPTY(manager->events) ||
manager->exit || manager->stop_exec_queue)
return;
@ -811,9 +805,7 @@ static void event_queue_start(Manager *manager) {
return;
}
udev_list_node_foreach(loop, &manager->events) {
struct event *event = node_to_event(loop);
LIST_FOREACH(event,event,manager->events) {
if (event->state != EVENT_QUEUED)
continue;
@ -826,11 +818,9 @@ static void event_queue_start(Manager *manager) {
}
static void event_queue_cleanup(Manager *manager, enum event_state match_type) {
struct udev_list_node *loop, *tmp;
udev_list_node_foreach_safe(loop, tmp, &manager->events) {
struct event *event = node_to_event(loop);
struct event *event, *tmp;
LIST_FOREACH_SAFE(event, event, tmp, manager->events) {
if (match_type != EVENT_UNDEF && match_type != event->state)
continue;
@ -1247,7 +1237,7 @@ static int on_post(sd_event_source *s, void *userdata) {
assert(manager);
if (udev_list_node_is_empty(&manager->events)) {
if (LIST_IS_EMPTY(manager->events)) {
/* no pending events */
if (!hashmap_isempty(manager->workers)) {
/* there are idle workers */
@ -1532,7 +1522,7 @@ static int manager_new(Manager **ret, int fd_ctrl, int fd_uevent, const char *cg
if (!manager->rules)
return log_error_errno(ENOMEM, "error reading rules");
udev_list_node_init(&manager->events);
LIST_HEAD_INIT(manager->events);
udev_list_init(manager->udev, &manager->properties, true);
manager->cgroup = cgroup;