chiark / gitweb /
journal: introduce sd_journal_wait() to simplify writing synchronous clients
[elogind.git] / src / journal / sd-journal.c
index 7588459..149dc10 100644 (file)
@@ -24,6 +24,7 @@
 #include <stddef.h>
 #include <unistd.h>
 #include <sys/inotify.h>
+#include <sys/poll.h>
 
 #include "sd-journal.h"
 #include "journal-def.h"
@@ -1622,6 +1623,20 @@ _public_ int sd_journal_process(sd_journal *j) {
         }
 }
 
+_public_ int sd_journal_wait(sd_journal *j, uint64_t timeout_usec) {
+        int r, k;
+
+        assert(j);
+
+        r = fd_wait_for_event(j->inotify_fd, POLLIN, timeout_usec);
+        k = sd_journal_process(j);
+
+        if (r < 0)
+                return r;
+
+        return k;
+}
+
 _public_ int sd_journal_get_cutoff_realtime_usec(sd_journal *j, uint64_t *from, uint64_t *to) {
         Iterator i;
         JournalFile *f;