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/>.
31 #include "sd-journal.h"
34 static bool arg_follow = true;
36 int main(int argc, char *argv[]) {
40 log_set_max_level(LOG_DEBUG);
41 log_set_target(LOG_TARGET_CONSOLE);
43 log_parse_environment();
46 r = sd_journal_open(&j);
48 log_error("Failed to open journal: %s", strerror(-r));
52 for (i = 1; i < argc; i++) {
53 r = sd_journal_add_match(j, argv[i], strlen(argv[i]));
55 log_error("Failed to add match: %s", strerror(-r));
60 fd = sd_journal_get_fd(j);
62 log_error("Failed to get wakeup fd: %s", strerror(-fd));
66 r = sd_journal_seek_head(j);
68 log_error("Failed to seek to head: %s", strerror(-r));
75 while (sd_journal_next(j) > 0) {
79 uint64_t realtime = 0, monotonic = 0;
81 r = sd_journal_get_cursor(j, &cursor);
83 log_error("Failed to get cursor: %s", strerror(-r));
87 printf("entry: %s\n", cursor);
90 sd_journal_get_realtime_usec(j, &realtime);
91 sd_journal_get_monotonic_usec(j, &monotonic, NULL);
92 printf("realtime: %llu\n"
94 (unsigned long long) realtime,
95 (unsigned long long) monotonic);
97 SD_JOURNAL_FOREACH_DATA(j, data, length)
98 printf("\t%.*s\n", (int) length, (const char*) data);
106 pollfd.events = POLLIN;
108 if (poll(&pollfd, 1, -1) < 0) {
112 log_error("poll(): %m");
117 r = sd_journal_process(j);
119 log_error("Failed to process: %s", strerror(-r));
128 return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;