]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/libudev/libudev-queue.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright © 2009 Alan Jenkins <alan-jenkins@tuffmail.co.uk>
9 #include <sys/inotify.h>
12 #include "alloc-util.h"
15 #include "libudev-private.h"
18 * SECTION:libudev-queue
19 * @short_description: access to currently active events
21 * This exports the current state of the udev processing queue.
27 * Opaque object representing the current event queue in the udev daemon.
37 * @udev: udev library context
39 * The initial refcount is 1, and needs to be decremented to
40 * release the resources of the udev queue context.
42 * Returns: the udev queue context, or #NULL on error.
44 _public_
struct udev_queue
*udev_queue_new(struct udev
*udev
) {
45 struct udev_queue
*udev_queue
;
47 udev_queue
= new(struct udev_queue
, 1);
48 if (udev_queue
== NULL
) {
53 *udev_queue
= (struct udev_queue
) {
62 static struct udev_queue
*udev_queue_free(struct udev_queue
*udev_queue
) {
65 safe_close(udev_queue
->fd
);
66 return mfree(udev_queue
);
71 * @udev_queue: udev queue context
73 * Take a reference of a udev queue context.
75 * Returns: the same udev queue context.
80 * @udev_queue: udev queue context
82 * Drop a reference of a udev queue context. If the refcount reaches zero,
83 * the resources of the queue context will be released.
87 DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(struct udev_queue
, udev_queue
, udev_queue_free
);
90 * udev_queue_get_udev:
91 * @udev_queue: udev queue context
93 * Retrieve the udev library context the queue context was created with.
95 * Returns: the udev library context.
97 _public_
struct udev
*udev_queue_get_udev(struct udev_queue
*udev_queue
) {
98 assert_return_errno(udev_queue
, NULL
, EINVAL
);
100 return udev_queue
->udev
;
104 * udev_queue_get_kernel_seqnum:
105 * @udev_queue: udev queue context
107 * This function is deprecated.
111 _public_
unsigned long long int udev_queue_get_kernel_seqnum(struct udev_queue
*udev_queue
) {
116 * udev_queue_get_udev_seqnum:
117 * @udev_queue: udev queue context
119 * This function is deprecated.
123 _public_
unsigned long long int udev_queue_get_udev_seqnum(struct udev_queue
*udev_queue
) {
128 * udev_queue_get_udev_is_active:
129 * @udev_queue: udev queue context
131 * Check if udev is active on the system.
133 * Returns: a flag indicating if udev is active.
135 _public_
int udev_queue_get_udev_is_active(struct udev_queue
*udev_queue
) {
136 return access("/run/udev/control", F_OK
) >= 0;
140 * udev_queue_get_queue_is_empty:
141 * @udev_queue: udev queue context
143 * Check if udev is currently processing any events.
145 * Returns: a flag indicating if udev is currently handling events.
147 _public_
int udev_queue_get_queue_is_empty(struct udev_queue
*udev_queue
) {
148 return access("/run/udev/queue", F_OK
) < 0;
152 * udev_queue_get_seqnum_sequence_is_finished:
153 * @udev_queue: udev queue context
154 * @start: first event sequence number
155 * @end: last event sequence number
157 * This function is deprecated, it just returns the result of
158 * udev_queue_get_queue_is_empty().
160 * Returns: a flag indicating if udev is currently handling events.
162 _public_
int udev_queue_get_seqnum_sequence_is_finished(struct udev_queue
*udev_queue
,
163 unsigned long long int start
, unsigned long long int end
) {
164 return udev_queue_get_queue_is_empty(udev_queue
);
168 * udev_queue_get_seqnum_is_finished:
169 * @udev_queue: udev queue context
170 * @seqnum: sequence number
172 * This function is deprecated, it just returns the result of
173 * udev_queue_get_queue_is_empty().
175 * Returns: a flag indicating if udev is currently handling events.
177 _public_
int udev_queue_get_seqnum_is_finished(struct udev_queue
*udev_queue
, unsigned long long int seqnum
) {
178 return udev_queue_get_queue_is_empty(udev_queue
);
182 * udev_queue_get_queued_list_entry:
183 * @udev_queue: udev queue context
185 * This function is deprecated.
189 _public_
struct udev_list_entry
*udev_queue_get_queued_list_entry(struct udev_queue
*udev_queue
) {
196 * @udev_queue: udev queue context
198 * Returns: a file descriptor to watch for a queue to become empty.
200 _public_
int udev_queue_get_fd(struct udev_queue
*udev_queue
) {
201 _cleanup_close_
int fd
= -1;
203 assert_return(udev_queue
, -EINVAL
);
205 if (udev_queue
->fd
>= 0)
206 return udev_queue
->fd
;
208 fd
= inotify_init1(IN_CLOEXEC
);
212 if (inotify_add_watch(fd
, "/run/udev" , IN_DELETE
) < 0)
215 udev_queue
->fd
= TAKE_FD(fd
);
216 return udev_queue
->fd
;
221 * @udev_queue: udev queue context
223 * Returns: the result of clearing the watch for queue changes.
225 _public_
int udev_queue_flush(struct udev_queue
*udev_queue
) {
228 assert_return(udev_queue
, -EINVAL
);
230 if (udev_queue
->fd
< 0)
233 r
= flush_fd(udev_queue
->fd
);