]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/libudev/libudev-queue.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2008-2012 Kay Sievers <kay@vrfy.org>
6 Copyright 2009 Alan Jenkins <alan-jenkins@tuffmail.co.uk>
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
25 #include <sys/inotify.h>
28 #include "alloc-util.h"
31 #include "libudev-private.h"
34 * SECTION:libudev-queue
35 * @short_description: access to currently active events
37 * This exports the current state of the udev processing queue.
43 * Opaque object representing the current event queue in the udev daemon.
53 * @udev: udev library context
55 * The initial refcount is 1, and needs to be decremented to
56 * release the resources of the udev queue context.
58 * Returns: the udev queue context, or #NULL on error.
60 _public_
struct udev_queue
*udev_queue_new(struct udev
*udev
)
62 struct udev_queue
*udev_queue
;
69 udev_queue
= new0(struct udev_queue
, 1);
70 if (udev_queue
== NULL
) {
75 udev_queue
->refcount
= 1;
76 udev_queue
->udev
= udev
;
83 * @udev_queue: udev queue context
85 * Take a reference of a udev queue context.
87 * Returns: the same udev queue context.
89 _public_
struct udev_queue
*udev_queue_ref(struct udev_queue
*udev_queue
)
91 if (udev_queue
== NULL
)
94 udev_queue
->refcount
++;
100 * @udev_queue: udev queue context
102 * Drop a reference of a udev queue context. If the refcount reaches zero,
103 * the resources of the queue context will be released.
107 _public_
struct udev_queue
*udev_queue_unref(struct udev_queue
*udev_queue
)
109 if (udev_queue
== NULL
)
112 udev_queue
->refcount
--;
113 if (udev_queue
->refcount
> 0)
116 safe_close(udev_queue
->fd
);
123 * udev_queue_get_udev:
124 * @udev_queue: udev queue context
126 * Retrieve the udev library context the queue context was created with.
128 * Returns: the udev library context.
130 _public_
struct udev
*udev_queue_get_udev(struct udev_queue
*udev_queue
)
132 if (udev_queue
== NULL
) {
136 return udev_queue
->udev
;
140 * udev_queue_get_kernel_seqnum:
141 * @udev_queue: udev queue context
143 * This function is deprecated.
147 _public_
unsigned long long int udev_queue_get_kernel_seqnum(struct udev_queue
*udev_queue
)
153 * udev_queue_get_udev_seqnum:
154 * @udev_queue: udev queue context
156 * This function is deprecated.
160 _public_
unsigned long long int udev_queue_get_udev_seqnum(struct udev_queue
*udev_queue
)
166 * udev_queue_get_udev_is_active:
167 * @udev_queue: udev queue context
169 * Check if udev is active on the system.
171 * Returns: a flag indicating if udev is active.
173 _public_
int udev_queue_get_udev_is_active(struct udev_queue
*udev_queue
)
175 return access("/run/udev/control", F_OK
) >= 0;
179 * udev_queue_get_queue_is_empty:
180 * @udev_queue: udev queue context
182 * Check if udev is currently processing any events.
184 * Returns: a flag indicating if udev is currently handling events.
186 _public_
int udev_queue_get_queue_is_empty(struct udev_queue
*udev_queue
)
188 return access("/run/udev/queue", F_OK
) < 0;
192 * udev_queue_get_seqnum_sequence_is_finished:
193 * @udev_queue: udev queue context
194 * @start: first event sequence number
195 * @end: last event sequence number
197 * This function is deprecated, it just returns the result of
198 * udev_queue_get_queue_is_empty().
200 * Returns: a flag indicating if udev is currently handling events.
202 _public_
int udev_queue_get_seqnum_sequence_is_finished(struct udev_queue
*udev_queue
,
203 unsigned long long int start
, unsigned long long int end
)
205 return udev_queue_get_queue_is_empty(udev_queue
);
209 * udev_queue_get_seqnum_is_finished:
210 * @udev_queue: udev queue context
211 * @seqnum: sequence number
213 * This function is deprecated, it just returns the result of
214 * udev_queue_get_queue_is_empty().
216 * Returns: a flag indicating if udev is currently handling events.
218 _public_
int udev_queue_get_seqnum_is_finished(struct udev_queue
*udev_queue
, unsigned long long int seqnum
)
220 return udev_queue_get_queue_is_empty(udev_queue
);
224 * udev_queue_get_queued_list_entry:
225 * @udev_queue: udev queue context
227 * This function is deprecated.
231 _public_
struct udev_list_entry
*udev_queue_get_queued_list_entry(struct udev_queue
*udev_queue
)
239 * @udev_queue: udev queue context
241 * Returns: a file descriptor to watch for a queue to become empty.
243 _public_
int udev_queue_get_fd(struct udev_queue
*udev_queue
) {
247 if (udev_queue
->fd
>= 0)
248 return udev_queue
->fd
;
250 fd
= inotify_init1(IN_CLOEXEC
);
254 r
= inotify_add_watch(fd
, "/run/udev" , IN_DELETE
);
267 * @udev_queue: udev queue context
269 * Returns: the result of clearing the watch for queue changes.
271 _public_
int udev_queue_flush(struct udev_queue
*udev_queue
) {
272 if (udev_queue
->fd
< 0)
275 return flush_fd(udev_queue
->fd
);