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