]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/journal/test-journal-enum.c
Merge pull request #11827 from keszybz/pkgconfig-variables
[thirdparty/systemd.git] / src / journal / test-journal-enum.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #include <stdio.h>
4
5 #include "sd-journal.h"
6
7 #include "journal-internal.h"
8 #include "log.h"
9 #include "macro.h"
10 #include "tests.h"
11
12 int main(int argc, char *argv[]) {
13 unsigned n = 0;
14 _cleanup_(sd_journal_closep) sd_journal *j = NULL;
15
16 test_setup_logging(LOG_DEBUG);
17
18 assert_se(sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY) >= 0);
19
20 assert_se(sd_journal_add_match(j, "_TRANSPORT=syslog", 0) >= 0);
21 assert_se(sd_journal_add_match(j, "_UID=0", 0) >= 0);
22
23 SD_JOURNAL_FOREACH_BACKWARDS(j) {
24 const void *d;
25 size_t l;
26
27 assert_se(sd_journal_get_data(j, "MESSAGE", &d, &l) >= 0);
28
29 printf("%.*s\n", (int) l, (char*) d);
30
31 n++;
32 if (n >= 10)
33 break;
34 }
35
36 return 0;
37 }