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