1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2011 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
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 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
26 #include "journal-file.h"
28 int main(int argc, char *argv[]) {
33 log_parse_environment();
36 r = journal_file_open("/var/log/journal/system.journal", O_RDONLY, 0644, &f);
38 r = journal_file_open("/run/log/journal/system.journal", O_RDONLY, 0644, &f);
41 log_error("Failed to open journal: %s", strerror(-r));
49 r = journal_file_next_entry(f, o, &o, &offset);
51 log_error("Failed to read journal: %s", strerror(-r));
58 printf("entry: %llu\n", (unsigned long long) le64toh(o->entry.seqnum));
60 n = journal_file_entry_n_items(o);
61 for (i = 0; i < n; i++) {
64 p = le64toh(o->entry.items[i].object_offset);
65 r = journal_file_move_to_object(f, p, OBJECT_DATA, &o);
67 log_error("Failed to move to data: %s", strerror(-r));
71 l = o->object.size - offsetof(Object, data.payload);
72 printf("\t[%.*s]\n", (int) l, o->data.payload);
74 r = journal_file_move_to_object(f, offset, OBJECT_ENTRY, &o);
76 log_error("Failed to move back to entry: %s", strerror(-r));
83 journal_file_close(f);