chiark / gitweb /
journal: implement parallel file traversal
[elogind.git] / src / journal / journalctl.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 /***
4   This file is part of systemd.
5
6   Copyright 2011 Lennart Poettering
7
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.
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   General Public License for more details.
17
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/>.
20 ***/
21
22 #include <fcntl.h>
23 #include <errno.h>
24 #include <stddef.h>
25 #include <string.h>
26 #include <stdio.h>
27 #include <unistd.h>
28 #include <stdlib.h>
29
30 #include "sd-journal.h"
31 #include "log.h"
32
33 int main(int argc, char *argv[]) {
34         int r;
35         sd_journal *j = NULL;
36
37         log_set_max_level(LOG_DEBUG);
38         log_set_target(LOG_TARGET_CONSOLE);
39
40         log_parse_environment();
41         log_open();
42
43         r = sd_journal_open(&j);
44         if (r < 0) {
45                 log_error("Failed to open journal: %s", strerror(-r));
46                 goto finish;
47         }
48
49         SD_JOURNAL_FOREACH(j) {
50                 const void *data;
51                 size_t length;
52                 char *cursor;
53
54                 r = sd_journal_get_cursor(j, &cursor);
55                 if (r < 0) {
56                         log_error("Failed to get cursor: %s", strerror(-r));
57                         goto finish;
58                 }
59
60                 printf("entry: %s\n", cursor);
61                 free(cursor);
62
63                 SD_JOURNAL_FOREACH_FIELD(j, data, length)
64                         printf("\t%.*s\n", (int) length, (const char*) data);
65         }
66
67 finish:
68         if (j)
69                 sd_journal_close(j);
70
71         return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
72 }