2 This file is part of systemd.
4 Copyright 2008-2012 Kay Sievers <kay@vrfy.org>
5 Copyright 2009 Alan Jenkins <alan-jenkins@tuffmail.co.uk>
7 systemd is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
12 systemd is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
25 #include <sys/inotify.h>
27 #include "libudev-private.h"
30 * SECTION:libudev-queue
31 * @short_description: access to currently active events
33 * This exports the current state of the udev processing queue.
39 * Opaque object representing the current event queue in the udev daemon.
49 * @udev: udev library context
51 * The initial refcount is 1, and needs to be decremented to
52 * release the resources of the udev queue context.
54 * Returns: the udev queue context, or #NULL on error.
56 _public_ struct udev_queue *udev_queue_new(struct udev *udev)
58 struct udev_queue *udev_queue;
63 udev_queue = new0(struct udev_queue, 1);
64 if (udev_queue == NULL)
67 udev_queue->refcount = 1;
68 udev_queue->udev = udev;
75 * @udev_queue: udev queue context
77 * Take a reference of a udev queue context.
79 * Returns: the same udev queue context.
81 _public_ struct udev_queue *udev_queue_ref(struct udev_queue *udev_queue)
83 if (udev_queue == NULL)
86 udev_queue->refcount++;
92 * @udev_queue: udev queue context
94 * Drop a reference of a udev queue context. If the refcount reaches zero,
95 * the resources of the queue context will be released.
99 _public_ struct udev_queue *udev_queue_unref(struct udev_queue *udev_queue)
101 if (udev_queue == NULL)
104 udev_queue->refcount--;
105 if (udev_queue->refcount > 0)
108 safe_close(udev_queue->fd);
115 * udev_queue_get_udev:
116 * @udev_queue: udev queue context
118 * Retrieve the udev library context the queue context was created with.
120 * Returns: the udev library context.
122 _public_ struct udev *udev_queue_get_udev(struct udev_queue *udev_queue)
124 if (udev_queue == NULL)
126 return udev_queue->udev;
130 * udev_queue_get_kernel_seqnum:
131 * @udev_queue: udev queue context
133 * This function is deprecated.
137 _public_ unsigned long long int udev_queue_get_kernel_seqnum(struct udev_queue *udev_queue)
143 * udev_queue_get_udev_seqnum:
144 * @udev_queue: udev queue context
146 * This function is deprecated.
150 _public_ unsigned long long int udev_queue_get_udev_seqnum(struct udev_queue *udev_queue)
156 * udev_queue_get_udev_is_active:
157 * @udev_queue: udev queue context
159 * Check if udev is active on the system.
161 * Returns: a flag indicating if udev is active.
163 _public_ int udev_queue_get_udev_is_active(struct udev_queue *udev_queue)
165 return access("/run/udev/control", F_OK) >= 0;
169 * udev_queue_get_queue_is_empty:
170 * @udev_queue: udev queue context
172 * Check if udev is currently processing any events.
174 * Returns: a flag indicating if udev is currently handling events.
176 _public_ int udev_queue_get_queue_is_empty(struct udev_queue *udev_queue)
178 return access("/run/udev/queue", F_OK) < 0;
182 * udev_queue_get_seqnum_sequence_is_finished:
183 * @udev_queue: udev queue context
184 * @start: first event sequence number
185 * @end: last event sequence number
187 * This function is deprecated, it just returns the result of
188 * udev_queue_get_queue_is_empty().
190 * Returns: a flag indicating if udev is currently handling events.
192 _public_ int udev_queue_get_seqnum_sequence_is_finished(struct udev_queue *udev_queue,
193 unsigned long long int start, unsigned long long int end)
195 return udev_queue_get_queue_is_empty(udev_queue);
199 * udev_queue_get_seqnum_is_finished:
200 * @udev_queue: udev queue context
201 * @seqnum: sequence number
203 * This function is deprecated, it just returns the result of
204 * udev_queue_get_queue_is_empty().
206 * Returns: a flag indicating if udev is currently handling events.
208 _public_ int udev_queue_get_seqnum_is_finished(struct udev_queue *udev_queue, unsigned long long int seqnum)
210 return udev_queue_get_queue_is_empty(udev_queue);
214 * udev_queue_get_queued_list_entry:
215 * @udev_queue: udev queue context
217 * This function is deprecated.
221 _public_ struct udev_list_entry *udev_queue_get_queued_list_entry(struct udev_queue *udev_queue)
228 * @udev_queue: udev queue context
230 * Returns: a file descriptor to watch for a queue to become empty.
232 _public_ int udev_queue_get_fd(struct udev_queue *udev_queue) {
236 if (udev_queue->fd >= 0)
237 return udev_queue->fd;
239 fd = inotify_init1(IN_CLOEXEC);
243 r = inotify_add_watch(fd, "/run/udev" , IN_DELETE);
256 * @udev_queue: udev queue context
258 * Returns: the result of clearing the watch for queue changes.
260 _public_ int udev_queue_flush(struct udev_queue *udev_queue) {
261 if (udev_queue->fd < 0)
264 return flush_fd(udev_queue->fd);