***/
#include <errno.h>
-#include <stddef.h>
-#include <stdlib.h>
-#include <sys/inotify.h>
#include <unistd.h>
#include "libudev.h"
#include "alloc-util.h"
#include "fd-util.h"
#include "io-util.h"
+#include "udev-util.h"
/**
* SECTION:libudev-queue
* Returns: a flag indicating if udev is currently handling events.
**/
_public_ int udev_queue_get_queue_is_empty(struct udev_queue *udev_queue) {
- return access("/run/udev/queue", F_OK) < 0;
+ return udev_queue_is_empty() > 0;
}
/**
* @start: first event sequence number
* @end: last event sequence number
*
- * This function is deprecated, it just returns the result of
- * udev_queue_get_queue_is_empty().
+ * This function is deprecated, and equivalent to udev_queue_get_queue_is_empty().
*
* Returns: a flag indicating if udev is currently handling events.
**/
_public_ int udev_queue_get_seqnum_sequence_is_finished(struct udev_queue *udev_queue,
unsigned long long int start, unsigned long long int end) {
- return udev_queue_get_queue_is_empty(udev_queue);
+ return udev_queue_is_empty() > 0;
}
/**
* @udev_queue: udev queue context
* @seqnum: sequence number
*
- * This function is deprecated, it just returns the result of
- * udev_queue_get_queue_is_empty().
+ * This function is deprecated, and equivalent to udev_queue_get_queue_is_empty().
*
* Returns: a flag indicating if udev is currently handling events.
**/
_public_ int udev_queue_get_seqnum_is_finished(struct udev_queue *udev_queue, unsigned long long int seqnum) {
- return udev_queue_get_queue_is_empty(udev_queue);
+ return udev_queue_is_empty() > 0;
}
/**
* Returns: a file descriptor to watch for a queue to become empty.
*/
_public_ int udev_queue_get_fd(struct udev_queue *udev_queue) {
- _cleanup_close_ int fd = -1;
+ int r;
assert_return(udev_queue, -EINVAL);
if (udev_queue->fd >= 0)
return udev_queue->fd;
- fd = inotify_init1(IN_CLOEXEC);
- if (fd < 0)
- return -errno;
-
- if (inotify_add_watch(fd, "/run/udev" , IN_DELETE) < 0)
- return -errno;
+ r = udev_queue_init();
+ if (r < 0)
+ return r;
- udev_queue->fd = TAKE_FD(fd);
- return udev_queue->fd;
+ return udev_queue->fd = r;
}
/**
#include <ctype.h>
#include <errno.h>
+#include <sys/inotify.h>
#include <unistd.h>
#include "alloc-util.h"
#include "device-util.h"
#include "env-file.h"
#include "escape.h"
+#include "fd-util.h"
#include "log.h"
#include "macro.h"
#include "parse-util.h"
}
return 0;
}
+
+int udev_queue_is_empty(void) {
+ return access("/run/udev/queue", F_OK) < 0 ?
+ (errno == ENOENT ? true : -errno) : false;
+}
+
+int udev_queue_init(void) {
+ _cleanup_close_ int fd = -1;
+
+ fd = inotify_init1(IN_CLOEXEC);
+ if (fd < 0)
+ return -errno;
+
+ if (inotify_add_watch(fd, "/run/udev" , IN_DELETE) < 0)
+ return -errno;
+
+ return TAKE_FD(fd);
+}
size_t udev_replace_whitespace(const char *str, char *to, size_t len);
size_t udev_replace_chars(char *str, const char *allow);
int udev_resolve_subsys_kernel(const char *string, char *result, size_t maxsize, bool read_value);
+
+int udev_queue_is_empty(void);
+int udev_queue_init(void);