Debian Codegraph @

man/journal-iterate-foreach.c

raw
1 /* SPDX-License-Identifier: MIT-0 */
2
3 #include <errno.h>
4 #include <stdio.h>
5 #include <systemd/sd-journal.h>
6
7 int main(int argc, char *argv[]) {
8 int r;
9 sd_journal *j;
10
11 r = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY);
12 if (r < 0) {
13 fprintf(stderr, "Failed to open journal: %s\n", strerror(-r));
14 return 1;
15 }
16 SD_JOURNAL_FOREACH(j) {
17 const char *d;
18 size_t l;
19
20 r = sd_journal_get_data(j, "MESSAGE", (const void **)&d, &l);
21 if (r < 0) {
22 fprintf(stderr, "Failed to read message field: %s\n", strerror(-r));
23 continue;
24 }
25
26 printf("%.*s\n", (int) l, d);
27 }
28 sd_journal_close(j);
29 return 0;
30 }