X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Flibudev%2Flibudev-queue.c;h=ae0b415e368d9f6a31894e7a75018f028935d289;hp=c32a7ef709a00b067176b057d51004656077f417;hb=93a1e66efd4b0f4cda29c467d20d0f7510c0b3a8;hpb=45e60962b7965f32755a76b79a28126299aac149;ds=inline diff --git a/src/libudev/libudev-queue.c b/src/libudev/libudev-queue.c index c32a7ef70..ae0b415e3 100644 --- a/src/libudev/libudev-queue.c +++ b/src/libudev/libudev-queue.c @@ -26,6 +26,7 @@ #include #include #include +#include #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,47 @@ _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" , 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); +} + +__asm__(".symver udev_queue_flush,udev_queue_flush@LIBUDEV_183"); +__asm__(".symver udev_queue_get_fd,udev_queue_get_fd@LIBUDEV_183");