]>
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/>.
25 #include <sys/inotify.h>
29 #include "libudev-private.h"
32 * SECTION:libudev-queue
33 * @short_description: access to currently active events
35 * This exports the current state of the udev processing queue.
41 * Opaque object representing the current event queue in the udev daemon.
51 * @udev: udev library context
53 * The initial refcount is 1, and needs to be decremented to
54 * release the resources of the udev queue context.
56 * Returns: the udev queue context, or #NULL on error.
58 _public_
struct udev_queue
*udev_queue_new(struct udev
*udev
)
60 struct udev_queue
*udev_queue
;
65 udev_queue
= new0(struct udev_queue
, 1);
66 if (udev_queue
== NULL
)
69 udev_queue
->refcount
= 1;
70 udev_queue
->udev
= udev
;
77 * @udev_queue: udev queue context
79 * Take a reference of a udev queue context.
81 * Returns: the same udev queue context.
83 _public_
struct udev_queue
*udev_queue_ref(struct udev_queue
*udev_queue
)
85 if (udev_queue
== NULL
)
88 udev_queue
->refcount
++;
94 * @udev_queue: udev queue context
96 * Drop a reference of a udev queue context. If the refcount reaches zero,
97 * the resources of the queue context will be released.
101 _public_
struct udev_queue
*udev_queue_unref(struct udev_queue
*udev_queue
)
103 if (udev_queue
== NULL
)
106 udev_queue
->refcount
--;
107 if (udev_queue
->refcount
> 0)
110 safe_close(udev_queue
->fd
);
117 * udev_queue_get_udev:
118 * @udev_queue: udev queue context
120 * Retrieve the udev library context the queue context was created with.
122 * Returns: the udev library context.
124 _public_
struct udev
*udev_queue_get_udev(struct udev_queue
*udev_queue
)
126 if (udev_queue
== NULL
)
128 return udev_queue
->udev
;
132 * udev_queue_get_kernel_seqnum:
133 * @udev_queue: udev queue context
135 * This function is deprecated.
139 _public_
unsigned long long int udev_queue_get_kernel_seqnum(struct udev_queue
*udev_queue
)
145 * udev_queue_get_udev_seqnum:
146 * @udev_queue: udev queue context
148 * This function is deprecated.
152 _public_
unsigned long long int udev_queue_get_udev_seqnum(struct udev_queue
*udev_queue
)
158 * udev_queue_get_udev_is_active:
159 * @udev_queue: udev queue context
161 * Check if udev is active on the system.
163 * Returns: a flag indicating if udev is active.
165 _public_
int udev_queue_get_udev_is_active(struct udev_queue
*udev_queue
)
167 return access("/run/udev/control", F_OK
) >= 0;
171 * udev_queue_get_queue_is_empty:
172 * @udev_queue: udev queue context
174 * Check if udev is currently processing any events.
176 * Returns: a flag indicating if udev is currently handling events.
178 _public_
int udev_queue_get_queue_is_empty(struct udev_queue
*udev_queue
)
180 return access("/run/udev/queue", F_OK
) < 0;
184 * udev_queue_get_seqnum_sequence_is_finished:
185 * @udev_queue: udev queue context
186 * @start: first event sequence number
187 * @end: last event sequence number
189 * This function is deprecated, it just returns the result of
190 * udev_queue_get_queue_is_empty().
192 * Returns: a flag indicating if udev is currently handling events.
194 _public_
int udev_queue_get_seqnum_sequence_is_finished(struct udev_queue
*udev_queue
,
195 unsigned long long int start
, unsigned long long int end
)
197 return udev_queue_get_queue_is_empty(udev_queue
);
201 * udev_queue_get_seqnum_is_finished:
202 * @udev_queue: udev queue context
203 * @seqnum: sequence number
205 * This function is deprecated, it just returns the result of
206 * udev_queue_get_queue_is_empty().
208 * Returns: a flag indicating if udev is currently handling events.
210 _public_
int udev_queue_get_seqnum_is_finished(struct udev_queue
*udev_queue
, unsigned long long int seqnum
)
212 return udev_queue_get_queue_is_empty(udev_queue
);
216 * udev_queue_get_queued_list_entry:
217 * @udev_queue: udev queue context
219 * This function is deprecated.
223 _public_
struct udev_list_entry
*udev_queue_get_queued_list_entry(struct udev_queue
*udev_queue
)
230 * @udev_queue: udev queue context
232 * Returns: a file descriptor to watch for a queue to become empty.
234 _public_
int udev_queue_get_fd(struct udev_queue
*udev_queue
) {
238 if (udev_queue
->fd
>= 0)
239 return udev_queue
->fd
;
241 fd
= inotify_init1(IN_CLOEXEC
);
245 r
= inotify_add_watch(fd
, "/run/udev" , IN_DELETE
);
258 * @udev_queue: udev queue context
260 * Returns: the result of clearing the watch for queue changes.
262 _public_
int udev_queue_flush(struct udev_queue
*udev_queue
) {
263 if (udev_queue
->fd
< 0)
266 return flush_fd(udev_queue
->fd
);