]>
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);
50 return_with_errno(NULL
, ENOMEM
);
52 *udev_queue
= (struct udev_queue
) {
61 static struct udev_queue
*udev_queue_free(struct udev_queue
*udev_queue
) {
64 safe_close(udev_queue
->fd
);
65 return mfree(udev_queue
);
70 * @udev_queue: udev queue context
72 * Take a reference of a udev queue context.
74 * Returns: the same udev queue context.
79 * @udev_queue: udev queue context
81 * Drop a reference of a udev queue context. If the refcount reaches zero,
82 * the resources of the queue context will be released.
86 DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(struct udev_queue
, udev_queue
, udev_queue_free
);
89 * udev_queue_get_udev:
90 * @udev_queue: udev queue context
92 * Retrieve the udev library context the queue context was created with.
94 * Returns: the udev library context.
96 _public_
struct udev
*udev_queue_get_udev(struct udev_queue
*udev_queue
) {
97 assert_return_errno(udev_queue
, NULL
, EINVAL
);
99 return udev_queue
->udev
;
103 * udev_queue_get_kernel_seqnum:
104 * @udev_queue: udev queue context
106 * This function is deprecated.
110 _public_
unsigned long long int udev_queue_get_kernel_seqnum(struct udev_queue
*udev_queue
) {
115 * udev_queue_get_udev_seqnum:
116 * @udev_queue: udev queue context
118 * This function is deprecated.
122 _public_
unsigned long long int udev_queue_get_udev_seqnum(struct udev_queue
*udev_queue
) {
127 * udev_queue_get_udev_is_active:
128 * @udev_queue: udev queue context
130 * Check if udev is active on the system.
132 * Returns: a flag indicating if udev is active.
134 _public_
int udev_queue_get_udev_is_active(struct udev_queue
*udev_queue
) {
135 return access("/run/udev/control", F_OK
) >= 0;
139 * udev_queue_get_queue_is_empty:
140 * @udev_queue: udev queue context
142 * Check if udev is currently processing any events.
144 * Returns: a flag indicating if udev is currently handling events.
146 _public_
int udev_queue_get_queue_is_empty(struct udev_queue
*udev_queue
) {
147 return access("/run/udev/queue", F_OK
) < 0;
151 * udev_queue_get_seqnum_sequence_is_finished:
152 * @udev_queue: udev queue context
153 * @start: first event sequence number
154 * @end: last event sequence number
156 * This function is deprecated, it just returns the result of
157 * udev_queue_get_queue_is_empty().
159 * Returns: a flag indicating if udev is currently handling events.
161 _public_
int udev_queue_get_seqnum_sequence_is_finished(struct udev_queue
*udev_queue
,
162 unsigned long long int start
, unsigned long long int end
) {
163 return udev_queue_get_queue_is_empty(udev_queue
);
167 * udev_queue_get_seqnum_is_finished:
168 * @udev_queue: udev queue context
169 * @seqnum: sequence number
171 * This function is deprecated, it just returns the result of
172 * udev_queue_get_queue_is_empty().
174 * Returns: a flag indicating if udev is currently handling events.
176 _public_
int udev_queue_get_seqnum_is_finished(struct udev_queue
*udev_queue
, unsigned long long int seqnum
) {
177 return udev_queue_get_queue_is_empty(udev_queue
);
181 * udev_queue_get_queued_list_entry:
182 * @udev_queue: udev queue context
184 * This function is deprecated.
188 _public_
struct udev_list_entry
*udev_queue_get_queued_list_entry(struct udev_queue
*udev_queue
) {
189 return_with_errno(NULL
, ENODATA
);
194 * @udev_queue: udev queue context
196 * Returns: a file descriptor to watch for a queue to become empty.
198 _public_
int udev_queue_get_fd(struct udev_queue
*udev_queue
) {
199 _cleanup_close_
int fd
= -1;
201 assert_return(udev_queue
, -EINVAL
);
203 if (udev_queue
->fd
>= 0)
204 return udev_queue
->fd
;
206 fd
= inotify_init1(IN_CLOEXEC
);
210 if (inotify_add_watch(fd
, "/run/udev" , IN_DELETE
) < 0)
213 udev_queue
->fd
= TAKE_FD(fd
);
214 return udev_queue
->fd
;
219 * @udev_queue: udev queue context
221 * Returns: the result of clearing the watch for queue changes.
223 _public_
int udev_queue_flush(struct udev_queue
*udev_queue
) {
226 assert_return(udev_queue
, -EINVAL
);
228 if (udev_queue
->fd
< 0)
231 r
= flush_fd(udev_queue
->fd
);