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