Debian Codegraph @

src/libsystemd/sd-journal/test-journal-enum.c

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include <stdio.h>
4
5 #include "sd-journal.h"
6
7 #include "tests.h"
8
9 int main(int argc, char *argv[]) {
10 unsigned n = 0;
11 _cleanup_(sd_journal_closep) sd_journal *j = NULL;
12
13 test_setup_logging(LOG_DEBUG);
14
15 ASSERT_OK(sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY | SD_JOURNAL_ASSUME_IMMUTABLE));
16
17 ASSERT_OK(sd_journal_add_match(j, "_TRANSPORT=syslog", SIZE_MAX));
18 ASSERT_OK(sd_journal_add_match(j, "_UID=0", SIZE_MAX));
19
20 SD_JOURNAL_FOREACH_BACKWARDS(j) {
21 const void *d;
22 size_t l;
23
24 ASSERT_OK(sd_journal_get_data(j, "MESSAGE", &d, &l));
25
26 printf("%.*s\n", (int) l, (char*) d);
27
28 n++;
29 if (n >= 10)
30 break;
31 }
32
33 return 0;
34 }