]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/journal/test-journal-enum.c
tree-wide: expose "p"-suffix unref calls in public APIs to make gcc cleanup easy
[thirdparty/systemd.git] / src / journal / test-journal-enum.c
CommitLineData
a4bcff5b
LP
1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3/***
4 This file is part of systemd.
5
6 Copyright 2012 Lennart Poettering
7
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20***/
21
22#include <stdio.h>
23
a4bcff5b 24#include "sd-journal.h"
07630cea 25
cf0fbc49 26#include "journal-internal.h"
07630cea 27#include "log.h"
763c7aa2 28#include "macro.h"
a4bcff5b
LP
29
30int main(int argc, char *argv[]) {
31 unsigned n = 0;
4afd3348 32 _cleanup_(sd_journal_closep) sd_journal*j = NULL;
a4bcff5b
LP
33
34 log_set_max_level(LOG_DEBUG);
35
36 assert_se(sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY) >= 0);
37
38 assert_se(sd_journal_add_match(j, "_TRANSPORT=syslog", 0) >= 0);
39 assert_se(sd_journal_add_match(j, "_UID=0", 0) >= 0);
40
41 SD_JOURNAL_FOREACH_BACKWARDS(j) {
42 const void *d;
43 size_t l;
44
45 assert_se(sd_journal_get_data(j, "MESSAGE", &d, &l) >= 0);
46
47 printf("%.*s\n", (int) l, (char*) d);
48
49 n ++;
50 if (n >= 10)
51 break;
52 }
53
a4bcff5b
LP
54 return 0;
55}