diff options
author | Kay Sievers <kay@vrfy.org> | 2014-06-27 17:42:44 +0200 |
---|---|---|
committer | Anthony G. Basile <blueness@gentoo.org> | 2014-07-01 07:20:47 -0400 |
commit | a31296d41eca0b996f31f9abe60fce33b036689e (patch) | |
tree | f3611c78d1314469d384287fcc260e4481f0da6e /src/libudev | |
parent | e17b263727b3f38a5a80ddb58d904e7b3307cc58 (diff) |
libudev: queue provide file descriptor to watch busy event queue
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'src/libudev')
-rw-r--r-- | src/libudev/libudev-queue.c | 46 | ||||
-rw-r--r-- | src/libudev/libudev.h | 2 | ||||
-rw-r--r-- | src/libudev/libudev.sym | 2 |
3 files changed, 50 insertions, 0 deletions
diff --git a/src/libudev/libudev-queue.c b/src/libudev/libudev-queue.c index c32a7ef709..d4334b440d 100644 --- a/src/libudev/libudev-queue.c +++ b/src/libudev/libudev-queue.c @@ -26,6 +26,7 @@ #include <string.h> #include <limits.h> #include <sys/stat.h> +#include <sys/inotify.h> #include "libudev.h" #include "libudev-private.h" @@ -45,6 +46,7 @@ struct udev_queue { struct udev *udev; int refcount; + int fd; }; /** @@ -69,6 +71,7 @@ _public_ struct udev_queue *udev_queue_new(struct udev *udev) udev_queue->refcount = 1; udev_queue->udev = udev; + udev_queue->fd = -1; return udev_queue; } @@ -107,6 +110,8 @@ _public_ struct udev_queue *udev_queue_unref(struct udev_queue *udev_queue) if (udev_queue->refcount > 0) return NULL; + safe_close(udev_queue->fd); + free(udev_queue); return NULL; } @@ -222,3 +227,44 @@ _public_ struct udev_list_entry *udev_queue_get_queued_list_entry(struct udev_qu { return NULL; } + +/** + * udev_queue_get_fd: + * @udev_queue: udev queue context + * + * Returns: a file descriptor to watch for a queue to become empty. + */ +_public_ int udev_queue_get_fd(struct udev_queue *udev_queue) { + int fd; + int r; + + if (udev_queue->fd >= 0) + return udev_queue->fd; + + fd = inotify_init1(IN_CLOEXEC); + if (fd < 0) + return -errno; + + r = inotify_add_watch(fd, "/run/udev/queue" , IN_DELETE); + if (r < 0) { + r = -errno; + close(fd); + return r; + } + + udev_queue->fd = fd; + return fd; +} + +/** + * udev_queue_flush: + * @udev_queue: udev queue context + * + * Returns: the result of clearing the watch for queue changes. + */ +_public_ int udev_queue_flush(struct udev_queue *udev_queue) { + if (udev_queue->fd < 0) + return -EINVAL; + + return flush_fd(udev_queue->fd); +} diff --git a/src/libudev/libudev.h b/src/libudev/libudev.h index ceb89bd593..4f2f11502c 100644 --- a/src/libudev/libudev.h +++ b/src/libudev/libudev.h @@ -177,6 +177,8 @@ int udev_queue_get_queue_is_empty(struct udev_queue *udev_queue); int udev_queue_get_seqnum_is_finished(struct udev_queue *udev_queue, unsigned long long int seqnum) __attribute__ ((deprecated)); int udev_queue_get_seqnum_sequence_is_finished(struct udev_queue *udev_queue, unsigned long long int start, unsigned long long int end) __attribute__ ((deprecated)); +int udev_queue_get_fd(struct udev_queue *udev_queue); +int udev_queue_flush(struct udev_queue *udev_queue); struct udev_list_entry *udev_queue_get_queued_list_entry(struct udev_queue *udev_queue) __attribute__ ((deprecated)); /* diff --git a/src/libudev/libudev.sym b/src/libudev/libudev.sym index 920e7e61eb..7062e29bda 100644 --- a/src/libudev/libudev.sym +++ b/src/libudev/libudev.sym @@ -82,6 +82,8 @@ global: udev_queue_get_udev; udev_queue_get_udev_is_active; udev_queue_get_udev_seqnum; + udev_queue_get_fd; + udev_queue_flush; udev_queue_new; udev_queue_ref; udev_queue_unref; |