]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/journal-iterate-poll.c
Merge pull request #31648 from neighbourhoodie/review-content
[thirdparty/systemd.git] / man / journal-iterate-poll.c
1 /* SPDX-License-Identifier: MIT-0 */
2
3 #define _GNU_SOURCE 1
4 #include <poll.h>
5 #include <time.h>
6 #include <systemd/sd-journal.h>
7
8 int wait_for_changes(sd_journal *j) {
9 uint64_t t;
10 int msec;
11 struct pollfd pollfd;
12
13 sd_journal_get_timeout(j, &t);
14 if (t == (uint64_t) -1)
15 msec = -1;
16 else {
17 struct timespec ts;
18 uint64_t n;
19 clock_gettime(CLOCK_MONOTONIC, &ts);
20 n = (uint64_t) ts.tv_sec * 1000000 + ts.tv_nsec / 1000;
21 msec = t > n ? (int) ((t - n + 999) / 1000) : 0;
22 }
23
24 pollfd.fd = sd_journal_get_fd(j);
25 pollfd.events = sd_journal_get_events(j);
26 poll(&pollfd, 1, msec);
27 return sd_journal_process(j);
28 }