]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/libudev/libudev-queue.c
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/>.
24 #include <sys/inotify.h>
27 #include "alloc-util.h"
30 #include "libudev-private.h"
33 * SECTION:libudev-queue
34 * @short_description: access to currently active events
36 * This exports the current state of the udev processing queue.
42 * Opaque object representing the current event queue in the udev daemon.
52 * @udev: udev library context
54 * The initial refcount is 1, and needs to be decremented to
55 * release the resources of the udev queue context.
57 * Returns: the udev queue context, or #NULL on error.
59 _public_
struct udev_queue
*udev_queue_new(struct udev
*udev
)
61 struct udev_queue
*udev_queue
;
66 udev_queue
= new0(struct udev_queue
, 1);
67 if (udev_queue
== NULL
)
70 udev_queue
->refcount
= 1;
71 udev_queue
->udev
= udev
;
78 * @udev_queue: udev queue context
80 * Take a reference of a udev queue context.
82 * Returns: the same udev queue context.
84 _public_
struct udev_queue
*udev_queue_ref(struct udev_queue
*udev_queue
)
86 if (udev_queue
== NULL
)
89 udev_queue
->refcount
++;
95 * @udev_queue: udev queue context
97 * Drop a reference of a udev queue context. If the refcount reaches zero,
98 * the resources of the queue context will be released.
102 _public_
struct udev_queue
*udev_queue_unref(struct udev_queue
*udev_queue
)
104 if (udev_queue
== NULL
)
107 udev_queue
->refcount
--;
108 if (udev_queue
->refcount
> 0)
111 safe_close(udev_queue
->fd
);
118 * udev_queue_get_udev:
119 * @udev_queue: udev queue context
121 * Retrieve the udev library context the queue context was created with.
123 * Returns: the udev library context.
125 _public_
struct udev
*udev_queue_get_udev(struct udev_queue
*udev_queue
)
127 if (udev_queue
== NULL
)
129 return udev_queue
->udev
;
133 * udev_queue_get_kernel_seqnum:
134 * @udev_queue: udev queue context
136 * This function is deprecated.
140 _public_
unsigned long long int udev_queue_get_kernel_seqnum(struct udev_queue
*udev_queue
)
146 * udev_queue_get_udev_seqnum:
147 * @udev_queue: udev queue context
149 * This function is deprecated.
153 _public_
unsigned long long int udev_queue_get_udev_seqnum(struct udev_queue
*udev_queue
)
159 * udev_queue_get_udev_is_active:
160 * @udev_queue: udev queue context
162 * Check if udev is active on the system.
164 * Returns: a flag indicating if udev is active.
166 _public_
int udev_queue_get_udev_is_active(struct udev_queue
*udev_queue
)
168 return access("/run/udev/control", F_OK
) >= 0;
172 * udev_queue_get_queue_is_empty:
173 * @udev_queue: udev queue context
175 * Check if udev is currently processing any events.
177 * Returns: a flag indicating if udev is currently handling events.
179 _public_
int udev_queue_get_queue_is_empty(struct udev_queue
*udev_queue
)
181 return access("/run/udev/queue", F_OK
) < 0;
185 * udev_queue_get_seqnum_sequence_is_finished:
186 * @udev_queue: udev queue context
187 * @start: first event sequence number
188 * @end: last event sequence number
190 * This function is deprecated, it just returns the result of
191 * udev_queue_get_queue_is_empty().
193 * Returns: a flag indicating if udev is currently handling events.
195 _public_
int udev_queue_get_seqnum_sequence_is_finished(struct udev_queue
*udev_queue
,
196 unsigned long long int start
, unsigned long long int end
)
198 return udev_queue_get_queue_is_empty(udev_queue
);
202 * udev_queue_get_seqnum_is_finished:
203 * @udev_queue: udev queue context
204 * @seqnum: sequence number
206 * This function is deprecated, it just returns the result of
207 * udev_queue_get_queue_is_empty().
209 * Returns: a flag indicating if udev is currently handling events.
211 _public_
int udev_queue_get_seqnum_is_finished(struct udev_queue
*udev_queue
, unsigned long long int seqnum
)
213 return udev_queue_get_queue_is_empty(udev_queue
);
217 * udev_queue_get_queued_list_entry:
218 * @udev_queue: udev queue context
220 * This function is deprecated.
224 _public_
struct udev_list_entry
*udev_queue_get_queued_list_entry(struct udev_queue
*udev_queue
)
231 * @udev_queue: udev queue context
233 * Returns: a file descriptor to watch for a queue to become empty.
235 _public_
int udev_queue_get_fd(struct udev_queue
*udev_queue
) {
239 if (udev_queue
->fd
>= 0)
240 return udev_queue
->fd
;
242 fd
= inotify_init1(IN_CLOEXEC
);
246 r
= inotify_add_watch(fd
, "/run/udev" , IN_DELETE
);
259 * @udev_queue: udev queue context
261 * Returns: the result of clearing the watch for queue changes.
263 _public_
int udev_queue_flush(struct udev_queue
*udev_queue
) {
264 if (udev_queue
->fd
< 0)
267 return flush_fd(udev_queue
->fd
);