]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/libudev/libudev-queue.c
4d1a0adbf21a8150fb1ed672dadb08f617c6e55a
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>
28 #include "libudev-private.h"
31 * SECTION:libudev-queue
32 * @short_description: access to currently active events
34 * This exports the current state of the udev processing queue.
40 * Opaque object representing the current event queue in the udev daemon.
50 * @udev: udev library context
52 * The initial refcount is 1, and needs to be decremented to
53 * release the resources of the udev queue context.
55 * Returns: the udev queue context, or #NULL on error.
57 _public_
struct udev_queue
*udev_queue_new(struct udev
*udev
)
59 struct udev_queue
*udev_queue
;
64 udev_queue
= new0(struct udev_queue
, 1);
65 if (udev_queue
== NULL
)
68 udev_queue
->refcount
= 1;
69 udev_queue
->udev
= udev
;
76 * @udev_queue: udev queue context
78 * Take a reference of a udev queue context.
80 * Returns: the same udev queue context.
82 _public_
struct udev_queue
*udev_queue_ref(struct udev_queue
*udev_queue
)
84 if (udev_queue
== NULL
)
87 udev_queue
->refcount
++;
93 * @udev_queue: udev queue context
95 * Drop a reference of a udev queue context. If the refcount reaches zero,
96 * the resources of the queue context will be released.
100 _public_
struct udev_queue
*udev_queue_unref(struct udev_queue
*udev_queue
)
102 if (udev_queue
== NULL
)
105 udev_queue
->refcount
--;
106 if (udev_queue
->refcount
> 0)
109 safe_close(udev_queue
->fd
);
116 * udev_queue_get_udev:
117 * @udev_queue: udev queue context
119 * Retrieve the udev library context the queue context was created with.
121 * Returns: the udev library context.
123 _public_
struct udev
*udev_queue_get_udev(struct udev_queue
*udev_queue
)
125 if (udev_queue
== NULL
)
127 return udev_queue
->udev
;
131 * udev_queue_get_kernel_seqnum:
132 * @udev_queue: udev queue context
134 * This function is deprecated.
138 _public_
unsigned long long int udev_queue_get_kernel_seqnum(struct udev_queue
*udev_queue
)
144 * udev_queue_get_udev_seqnum:
145 * @udev_queue: udev queue context
147 * This function is deprecated.
151 _public_
unsigned long long int udev_queue_get_udev_seqnum(struct udev_queue
*udev_queue
)
157 * udev_queue_get_udev_is_active:
158 * @udev_queue: udev queue context
160 * Check if udev is active on the system.
162 * Returns: a flag indicating if udev is active.
164 _public_
int udev_queue_get_udev_is_active(struct udev_queue
*udev_queue
)
166 return access("/run/udev/control", F_OK
) >= 0;
170 * udev_queue_get_queue_is_empty:
171 * @udev_queue: udev queue context
173 * Check if udev is currently processing any events.
175 * Returns: a flag indicating if udev is currently handling events.
177 _public_
int udev_queue_get_queue_is_empty(struct udev_queue
*udev_queue
)
179 return access("/run/udev/queue", F_OK
) < 0;
183 * udev_queue_get_seqnum_sequence_is_finished:
184 * @udev_queue: udev queue context
185 * @start: first event sequence number
186 * @end: last event sequence number
188 * This function is deprecated, it just returns the result of
189 * udev_queue_get_queue_is_empty().
191 * Returns: a flag indicating if udev is currently handling events.
193 _public_
int udev_queue_get_seqnum_sequence_is_finished(struct udev_queue
*udev_queue
,
194 unsigned long long int start
, unsigned long long int end
)
196 return udev_queue_get_queue_is_empty(udev_queue
);
200 * udev_queue_get_seqnum_is_finished:
201 * @udev_queue: udev queue context
202 * @seqnum: sequence number
204 * This function is deprecated, it just returns the result of
205 * udev_queue_get_queue_is_empty().
207 * Returns: a flag indicating if udev is currently handling events.
209 _public_
int udev_queue_get_seqnum_is_finished(struct udev_queue
*udev_queue
, unsigned long long int seqnum
)
211 return udev_queue_get_queue_is_empty(udev_queue
);
215 * udev_queue_get_queued_list_entry:
216 * @udev_queue: udev queue context
218 * This function is deprecated.
222 _public_
struct udev_list_entry
*udev_queue_get_queued_list_entry(struct udev_queue
*udev_queue
)
229 * @udev_queue: udev queue context
231 * Returns: a file descriptor to watch for a queue to become empty.
233 _public_
int udev_queue_get_fd(struct udev_queue
*udev_queue
) {
237 if (udev_queue
->fd
>= 0)
238 return udev_queue
->fd
;
240 fd
= inotify_init1(IN_CLOEXEC
);
244 r
= inotify_add_watch(fd
, "/run/udev" , IN_DELETE
);
257 * @udev_queue: udev queue context
259 * Returns: the result of clearing the watch for queue changes.
261 _public_
int udev_queue_flush(struct udev_queue
*udev_queue
) {
262 if (udev_queue
->fd
< 0)
265 return flush_fd(udev_queue
->fd
);