]>
Commit | Line | Data |
---|---|---|
1fe6d37e | 1 | /* SPDX-License-Identifier: MIT-0 */ |
f4d74c61 | 2 | |
b4096cec | 3 | #include <errno.h> |
929f5263 | 4 | #include <stdio.h> |
929f5263 ZJS |
5 | #include <systemd/sd-journal.h> |
6 | ||
7 | int main(int argc, char *argv[]) { | |
8 | int r; | |
9 | sd_journal *j; | |
10 | r = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY); | |
11 | if (r < 0) { | |
b4096cec ZJS |
12 | errno = -r; |
13 | fprintf(stderr, "Failed to open journal: %m\n"); | |
929f5263 ZJS |
14 | return 1; |
15 | } | |
16 | for (;;) { | |
17 | const void *d; | |
18 | size_t l; | |
19 | r = sd_journal_next(j); | |
20 | if (r < 0) { | |
b4096cec ZJS |
21 | errno = -r; |
22 | fprintf(stderr, "Failed to iterate to next entry: %m\n"); | |
929f5263 ZJS |
23 | break; |
24 | } | |
25 | if (r == 0) { | |
26 | /* Reached the end, let's wait for changes, and try again */ | |
27 | r = sd_journal_wait(j, (uint64_t) -1); | |
28 | if (r < 0) { | |
b4096cec ZJS |
29 | errno = -r; |
30 | fprintf(stderr, "Failed to wait for changes: %m\n"); | |
929f5263 ZJS |
31 | break; |
32 | } | |
33 | continue; | |
34 | } | |
35 | r = sd_journal_get_data(j, "MESSAGE", &d, &l); | |
36 | if (r < 0) { | |
b4096cec ZJS |
37 | errno = -r; |
38 | fprintf(stderr, "Failed to read message field: %m\n"); | |
929f5263 ZJS |
39 | continue; |
40 | } | |
41 | printf("%.*s\n", (int) l, (const char*) d); | |
42 | } | |
43 | sd_journal_close(j); | |
44 | return 0; | |
45 | } |