a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering/***
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering This file is part of systemd.
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering Copyright 2012 Lennart Poettering
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering systemd is free software; you can redistribute it and/or modify it
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering under the terms of the GNU Lesser General Public License as published by
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering the Free Software Foundation; either version 2.1 of the License, or
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering (at your option) any later version.
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering systemd is distributed in the hope that it will be useful, but
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering Lesser General Public License for more details.
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering You should have received a copy of the GNU Lesser General Public License
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering***/
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering#include <stdio.h>
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering#include "sd-journal.h"
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering
cf0fbc49e67b55f8d346fc94de28c90113505297Thomas Hindoe Paaboel Andersen#include "journal-internal.h"
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering#include "log.h"
763c7aa288485cf5ab627fe1d25ff58e76f9dacbZbigniew Jędrzejewski-Szmek#include "macro.h"
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poetteringint main(int argc, char *argv[]) {
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering unsigned n = 0;
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_journal_closep) sd_journal*j = NULL;
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering log_set_max_level(LOG_DEBUG);
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering assert_se(sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY) >= 0);
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering assert_se(sd_journal_add_match(j, "_TRANSPORT=syslog", 0) >= 0);
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering assert_se(sd_journal_add_match(j, "_UID=0", 0) >= 0);
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering SD_JOURNAL_FOREACH_BACKWARDS(j) {
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering const void *d;
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering size_t l;
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering assert_se(sd_journal_get_data(j, "MESSAGE", &d, &l) >= 0);
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering printf("%.*s\n", (int) l, (char*) d);
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering n ++;
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering if (n >= 10)
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering break;
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering }
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering return 0;
a4bcff5ba36115495994e9f9ba66074471de76abLennart Poettering}