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 static int system_journal_open(JournalFile **f) {
36 r = sd_id128_get_machine(&machine);
40 fn = join("/var/log/journal/", sd_id128_to_string(machine, ids), "/system.journal", NULL);
44 r = journal_file_open(fn, O_RDONLY, 0640, NULL, f);
50 if (r < 0 && r != -ENOENT) {
51 log_error("Failed to open system journal: %s", strerror(-r));
55 fn = join("/run/log/journal/", ids, "/system.journal", NULL);
59 r = journal_file_open(fn, O_RDONLY, 0640, NULL, f);
63 log_error("Failed to open system journal: %s", strerror(-r));
70 int main(int argc, char *argv[]) {
75 log_parse_environment();
78 r = system_journal_open(&f);
80 log_error("Failed to open journal: %s", strerror(-r));
88 r = journal_file_next_entry(f, o, &o, &offset);
90 log_error("Failed to read journal: %s", strerror(-r));
97 printf("entry: %llu\n", (unsigned long long) le64toh(o->entry.seqnum));
99 n = journal_file_entry_n_items(o);
100 for (i = 0; i < n; i++) {
103 p = le64toh(o->entry.items[i].object_offset);
104 r = journal_file_move_to_object(f, p, OBJECT_DATA, &o);
106 log_error("Failed to move to data: %s", strerror(-r));
110 l = o->object.size - offsetof(Object, data.payload);
111 printf("\t[%.*s]\n", (int) l, o->data.payload);
113 r = journal_file_move_to_object(f, offset, OBJECT_ENTRY, &o);
115 log_error("Failed to move back to entry: %s", strerror(-r));
122 journal_file_close(f);