]>
Commit | Line | Data |
---|---|---|
87d2c1ff LP |
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> | |
3fbf9cbb LP |
25 | #include <string.h> |
26 | #include <stdio.h> | |
27 | #include <unistd.h> | |
28 | #include <stdlib.h> | |
87d2c1ff | 29 | |
3fbf9cbb LP |
30 | #include "sd-journal.h" |
31 | #include "log.h" | |
250d54b5 | 32 | |
87d2c1ff | 33 | int main(int argc, char *argv[]) { |
de7b95cd | 34 | int r, i; |
3fbf9cbb LP |
35 | sd_journal *j = NULL; |
36 | ||
37 | log_set_max_level(LOG_DEBUG); | |
38 | log_set_target(LOG_TARGET_CONSOLE); | |
87d2c1ff LP |
39 | |
40 | log_parse_environment(); | |
41 | log_open(); | |
42 | ||
3fbf9cbb | 43 | r = sd_journal_open(&j); |
87d2c1ff LP |
44 | if (r < 0) { |
45 | log_error("Failed to open journal: %s", strerror(-r)); | |
3fbf9cbb | 46 | goto finish; |
87d2c1ff LP |
47 | } |
48 | ||
de7b95cd LP |
49 | for (i = 1; i < argc; i++) { |
50 | r = sd_journal_add_match(j, argv[i], strlen(argv[i])); | |
51 | if (r < 0) { | |
52 | log_error("Failed to add match: %s", strerror(-r)); | |
53 | goto finish; | |
54 | } | |
55 | } | |
56 | ||
8725d60a LP |
57 | SD_JOURNAL_FOREACH_BEGIN(j) { |
58 | ||
3fbf9cbb LP |
59 | const void *data; |
60 | size_t length; | |
61 | char *cursor; | |
c2373f84 | 62 | uint64_t realtime = 0, monotonic = 0; |
87d2c1ff | 63 | |
3fbf9cbb | 64 | r = sd_journal_get_cursor(j, &cursor); |
87d2c1ff | 65 | if (r < 0) { |
3fbf9cbb | 66 | log_error("Failed to get cursor: %s", strerror(-r)); |
87d2c1ff LP |
67 | goto finish; |
68 | } | |
69 | ||
3fbf9cbb LP |
70 | printf("entry: %s\n", cursor); |
71 | free(cursor); | |
87d2c1ff | 72 | |
c2373f84 LP |
73 | sd_journal_get_realtime_usec(j, &realtime); |
74 | sd_journal_get_monotonic_usec(j, &monotonic); | |
75 | printf("realtime: %llu\n" | |
76 | "monotonic: %llu\n", | |
77 | (unsigned long long) realtime, | |
78 | (unsigned long long) monotonic); | |
79 | ||
8725d60a | 80 | SD_JOURNAL_FOREACH_DATA(j, data, length) |
3fbf9cbb | 81 | printf("\t%.*s\n", (int) length, (const char*) data); |
8725d60a LP |
82 | |
83 | } SD_JOURNAL_FOREACH_END(j); | |
87d2c1ff LP |
84 | |
85 | finish: | |
3fbf9cbb LP |
86 | if (j) |
87 | sd_journal_close(j); | |
87d2c1ff | 88 | |
3fbf9cbb | 89 | return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; |
87d2c1ff | 90 | } |