]>
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; | |
e84f70e1 | 10 | |
929f5263 ZJS |
11 | r = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY); |
12 | if (r < 0) { | |
e84f70e1 | 13 | fprintf(stderr, "Failed to open journal: %s\n", strerror(-r)); |
929f5263 ZJS |
14 | return 1; |
15 | } | |
e84f70e1 | 16 | |
929f5263 ZJS |
17 | for (;;) { |
18 | const void *d; | |
19 | size_t l; | |
20 | r = sd_journal_next(j); | |
21 | if (r < 0) { | |
e84f70e1 | 22 | fprintf(stderr, "Failed to iterate to next entry: %s\n", strerror(-r)); |
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) { | |
e84f70e1 | 29 | fprintf(stderr, "Failed to wait for changes: %s\n", strerror(-r)); |
929f5263 ZJS |
30 | break; |
31 | } | |
32 | continue; | |
33 | } | |
34 | r = sd_journal_get_data(j, "MESSAGE", &d, &l); | |
35 | if (r < 0) { | |
e84f70e1 | 36 | fprintf(stderr, "Failed to read message field: %s\n", strerror(-r)); |
929f5263 ZJS |
37 | continue; |
38 | } | |
39 | printf("%.*s\n", (int) l, (const char*) d); | |
40 | } | |
e84f70e1 | 41 | |
929f5263 ZJS |
42 | sd_journal_close(j); |
43 | return 0; | |
44 | } |