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/>.
29 #include <sys/inotify.h>
32 #include "libudev-private.h"
35 * SECTION:libudev-queue
36 * @short_description: access to currently active events
38 * This exports the current state of the udev processing queue.
44 * Opaque object representing the current event queue in the udev daemon.
54 * @udev: udev library context
56 * The initial refcount is 1, and needs to be decremented to
57 * release the resources of the udev queue context.
59 * Returns: the udev queue context, or #NULL on error.
61 _public_ struct udev_queue *udev_queue_new(struct udev *udev)
63 struct udev_queue *udev_queue;
68 udev_queue = new0(struct udev_queue, 1);
69 if (udev_queue == NULL)
72 udev_queue->refcount = 1;
73 udev_queue->udev = udev;
80 * @udev_queue: udev queue context
82 * Take a reference of a udev queue context.
84 * Returns: the same udev queue context.
86 _public_ struct udev_queue *udev_queue_ref(struct udev_queue *udev_queue)
88 if (udev_queue == NULL)
91 udev_queue->refcount++;
97 * @udev_queue: udev queue context
99 * Drop a reference of a udev queue context. If the refcount reaches zero,
100 * the resources of the queue context will be released.
104 _public_ struct udev_queue *udev_queue_unref(struct udev_queue *udev_queue)
106 if (udev_queue == NULL)
109 udev_queue->refcount--;
110 if (udev_queue->refcount > 0)
113 safe_close(udev_queue->fd);
120 * udev_queue_get_udev:
121 * @udev_queue: udev queue context
123 * Retrieve the udev library context the queue context was created with.
125 * Returns: the udev library context.
127 _public_ struct udev *udev_queue_get_udev(struct udev_queue *udev_queue)
129 if (udev_queue == NULL)
131 return udev_queue->udev;
135 * udev_queue_get_kernel_seqnum:
136 * @udev_queue: udev queue context
138 * This function is deprecated.
142 _public_ unsigned long long int udev_queue_get_kernel_seqnum(struct udev_queue *udev_queue)
148 * udev_queue_get_udev_seqnum:
149 * @udev_queue: udev queue context
151 * This function is deprecated.
155 _public_ unsigned long long int udev_queue_get_udev_seqnum(struct udev_queue *udev_queue)
161 * udev_queue_get_udev_is_active:
162 * @udev_queue: udev queue context
164 * Check if udev is active on the system.
166 * Returns: a flag indicating if udev is active.
168 _public_ int udev_queue_get_udev_is_active(struct udev_queue *udev_queue)
170 return access("/run/udev/control", F_OK) >= 0;
174 * udev_queue_get_queue_is_empty:
175 * @udev_queue: udev queue context
177 * Check if udev is currently processing any events.
179 * Returns: a flag indicating if udev is currently handling events.
181 _public_ int udev_queue_get_queue_is_empty(struct udev_queue *udev_queue)
183 return access("/run/udev/queue", F_OK) < 0;
187 * udev_queue_get_seqnum_sequence_is_finished:
188 * @udev_queue: udev queue context
189 * @start: first event sequence number
190 * @end: last event sequence number
192 * This function is deprecated, it just returns the result of
193 * udev_queue_get_queue_is_empty().
195 * Returns: a flag indicating if udev is currently handling events.
197 _public_ int udev_queue_get_seqnum_sequence_is_finished(struct udev_queue *udev_queue,
198 unsigned long long int start, unsigned long long int end)
200 return udev_queue_get_queue_is_empty(udev_queue);
204 * udev_queue_get_seqnum_is_finished:
205 * @udev_queue: udev queue context
206 * @seqnum: sequence number
208 * This function is deprecated, it just returns the result of
209 * udev_queue_get_queue_is_empty().
211 * Returns: a flag indicating if udev is currently handling events.
213 _public_ int udev_queue_get_seqnum_is_finished(struct udev_queue *udev_queue, unsigned long long int seqnum)
215 return udev_queue_get_queue_is_empty(udev_queue);
219 * udev_queue_get_queued_list_entry:
220 * @udev_queue: udev queue context
222 * This function is deprecated.
226 _public_ struct udev_list_entry *udev_queue_get_queued_list_entry(struct udev_queue *udev_queue)
233 * @udev_queue: udev queue context
235 * Returns: a file descriptor to watch for a queue to become empty.
237 _public_ int udev_queue_get_fd(struct udev_queue *udev_queue) {
241 if (udev_queue->fd >= 0)
242 return udev_queue->fd;
244 fd = inotify_init1(IN_CLOEXEC);
248 r = inotify_add_watch(fd, "/run/udev" , IN_DELETE);
261 * @udev_queue: udev queue context
263 * Returns: the result of clearing the watch for queue changes.
265 _public_ int udev_queue_flush(struct udev_queue *udev_queue) {
266 if (udev_queue->fd < 0)
269 return flush_fd(udev_queue->fd);