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