summaryrefslogtreecommitdiff
path: root/man/journal-iterate-poll.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-03-21 16:32:17 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-03-24 14:14:12 +0100
commit929f52632bc899ae9bd6932b667008f35acd25e4 (patch)
treea2ba3d73c995b7a50984ab496d1513da72144e40 /man/journal-iterate-poll.c
parentbc96c63c0522dc81c036dcd340369eb04df8d0e9 (diff)
downloadsystemd-929f52632bc899ae9bd6932b667008f35acd25e4.tar.gz
man: move examples out of sd_journal_get_fd into separate files
man/.dir-locals is to keep indentation under control. This makes it much easier to compile and run those examples, c.f. #7578. v2: - copy more of .dir-locals.el from the root to man/.dir-locals.el (I though emacs would inherit from the one in the parent dir, but it seems it just uses its own broken defaults, including indent-tabs-mode by default.)
Diffstat (limited to 'man/journal-iterate-poll.c')
-rw-r--r--man/journal-iterate-poll.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/man/journal-iterate-poll.c b/man/journal-iterate-poll.c
new file mode 100644
index 0000000000..174f6038fd
--- /dev/null
+++ b/man/journal-iterate-poll.c
@@ -0,0 +1,23 @@
+#include <poll.h>
+#include <systemd/sd-journal.h>
+
+int wait_for_changes(sd_journal *j) {
+ struct pollfd pollfd;
+ int msec;
+
+ sd_journal_get_timeout(m, &t);
+ if (t == (uint64_t) -1)
+ msec = -1;
+ else {
+ struct timespec ts;
+ uint64_t n;
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+ n = (uint64_t) ts.tv_sec * 1000000 + ts.tv_nsec / 1000;
+ msec = t > n ? (int) ((t - n + 999) / 1000) : 0;
+ }
+
+ pollfd.fd = sd_journal_get_fd(j);
+ pollfd.events = sd_journal_get_events(j);
+ poll(&pollfd, 1, msec);
+ return sd_journal_process(j);
+}