]>
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>
14 #include "alloc-util.h"
19 * SECTION:libudev-queue
20 * @short_description: access to currently active events
22 * This exports the current state of the udev processing queue.
28 * Opaque object representing the current event queue in the udev daemon.
38 * @udev: udev library context
40 * The initial refcount is 1, and needs to be decremented to
41 * release the resources of the udev queue context.
43 * Returns: the udev queue context, or #NULL on error.
45 _public_
struct udev_queue
*udev_queue_new(struct udev
*udev
) {
46 struct udev_queue
*udev_queue
;
48 udev_queue
= new(struct udev_queue
, 1);
54 *udev_queue
= (struct udev_queue
) {
63 static struct udev_queue
*udev_queue_free(struct udev_queue
*udev_queue
) {
66 safe_close(udev_queue
->fd
);
67 return mfree(udev_queue
);
72 * @udev_queue: udev queue context
74 * Take a reference of a udev queue context.
76 * Returns: the same udev queue context.
81 * @udev_queue: udev queue context
83 * Drop a reference of a udev queue context. If the refcount reaches zero,
84 * the resources of the queue context will be released.
88 DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(struct udev_queue
, udev_queue
, udev_queue_free
);
91 * udev_queue_get_udev:
92 * @udev_queue: udev queue context
94 * Retrieve the udev library context the queue context was created with.
96 * Returns: the udev library context.
98 _public_
struct udev
*udev_queue_get_udev(struct udev_queue
*udev_queue
) {
99 assert_return_errno(udev_queue
, NULL
, EINVAL
);
101 return udev_queue
->udev
;
105 * udev_queue_get_kernel_seqnum:
106 * @udev_queue: udev queue context
108 * This function is deprecated.
112 _public_
unsigned long long int udev_queue_get_kernel_seqnum(struct udev_queue
*udev_queue
) {
117 * udev_queue_get_udev_seqnum:
118 * @udev_queue: udev queue context
120 * This function is deprecated.
124 _public_
unsigned long long int udev_queue_get_udev_seqnum(struct udev_queue
*udev_queue
) {
129 * udev_queue_get_udev_is_active:
130 * @udev_queue: udev queue context
132 * Check if udev is active on the system.
134 * Returns: a flag indicating if udev is active.
136 _public_
int udev_queue_get_udev_is_active(struct udev_queue
*udev_queue
) {
137 return access("/run/udev/control", F_OK
) >= 0;
141 * udev_queue_get_queue_is_empty:
142 * @udev_queue: udev queue context
144 * Check if udev is currently processing any events.
146 * Returns: a flag indicating if udev is currently handling events.
148 _public_
int udev_queue_get_queue_is_empty(struct udev_queue
*udev_queue
) {
149 return access("/run/udev/queue", F_OK
) < 0;
153 * udev_queue_get_seqnum_sequence_is_finished:
154 * @udev_queue: udev queue context
155 * @start: first event sequence number
156 * @end: last event sequence number
158 * This function is deprecated, it just returns the result of
159 * udev_queue_get_queue_is_empty().
161 * Returns: a flag indicating if udev is currently handling events.
163 _public_
int udev_queue_get_seqnum_sequence_is_finished(struct udev_queue
*udev_queue
,
164 unsigned long long int start
, unsigned long long int end
) {
165 return udev_queue_get_queue_is_empty(udev_queue
);
169 * udev_queue_get_seqnum_is_finished:
170 * @udev_queue: udev queue context
171 * @seqnum: sequence number
173 * This function is deprecated, it just returns the result of
174 * udev_queue_get_queue_is_empty().
176 * Returns: a flag indicating if udev is currently handling events.
178 _public_
int udev_queue_get_seqnum_is_finished(struct udev_queue
*udev_queue
, unsigned long long int seqnum
) {
179 return udev_queue_get_queue_is_empty(udev_queue
);
183 * udev_queue_get_queued_list_entry:
184 * @udev_queue: udev queue context
186 * This function is deprecated.
190 _public_
struct udev_list_entry
*udev_queue_get_queued_list_entry(struct udev_queue
*udev_queue
) {
197 * @udev_queue: udev queue context
199 * Returns: a file descriptor to watch for a queue to become empty.
201 _public_
int udev_queue_get_fd(struct udev_queue
*udev_queue
) {
202 _cleanup_close_
int fd
= -1;
204 assert_return(udev_queue
, -EINVAL
);
206 if (udev_queue
->fd
>= 0)
207 return udev_queue
->fd
;
209 fd
= inotify_init1(IN_CLOEXEC
);
213 if (inotify_add_watch(fd
, "/run/udev" , IN_DELETE
) < 0)
216 udev_queue
->fd
= TAKE_FD(fd
);
217 return udev_queue
->fd
;
222 * @udev_queue: udev queue context
224 * Returns: the result of clearing the watch for queue changes.
226 _public_
int udev_queue_flush(struct udev_queue
*udev_queue
) {
229 assert_return(udev_queue
, -EINVAL
);
231 if (udev_queue
->fd
< 0)
234 r
= flush_fd(udev_queue
->fd
);