1 /* SPDX-License-Identifier: CC0-1.0 */
2 
3 #include <poll.h>
4 #include <time.h>
5 #include <systemd/sd-journal.h>
6 
wait_for_changes(sd_journal * j)7 int wait_for_changes(sd_journal *j) {
8   uint64_t t;
9   int msec;
10   struct pollfd pollfd;
11 
12   sd_journal_get_timeout(j, &t);
13   if (t == (uint64_t) -1)
14     msec = -1;
15   else {
16     struct timespec ts;
17     uint64_t n;
18     clock_gettime(CLOCK_MONOTONIC, &ts);
19     n = (uint64_t) ts.tv_sec * 1000000 + ts.tv_nsec / 1000;
20     msec = t > n ? (int) ((t - n + 999) / 1000) : 0;
21   }
22 
23   pollfd.fd = sd_journal_get_fd(j);
24   pollfd.events = sd_journal_get_events(j);
25   poll(&pollfd, 1, msec);
26   return sd_journal_process(j);
27 }
28