chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
journal: implement seek to head/tail
[elogind.git]
/
src
/
journal
/
journalctl.c
diff --git
a/src/journal/journalctl.c
b/src/journal/journalctl.c
index 7bcd842f6db5db8d3a2a1c8c3b19497210a00512..3e5ee1af967dd1244ef4747bb9bd0b253cf2b77a 100644
(file)
--- a/
src/journal/journalctl.c
+++ b/
src/journal/journalctl.c
@@
-22,70
+22,69
@@
#include <fcntl.h>
#include <errno.h>
#include <stddef.h>
#include <fcntl.h>
#include <errno.h>
#include <stddef.h>
+#include <string.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
-#include "journal-private.h"
+#include "sd-journal.h"
+#include "log.h"
int main(int argc, char *argv[]) {
int main(int argc, char *argv[]) {
- int r;
- JournalFile *f;
- Object *o = NULL;
+ int r, i;
+ sd_journal *j = NULL;
+
+ log_set_max_level(LOG_DEBUG);
+ log_set_target(LOG_TARGET_CONSOLE);
log_parse_environment();
log_open();
log_parse_environment();
log_open();
- r = journal_file_open("/var/log/journal/system.journal", O_RDONLY, 0644, &f);
- if (r == -ENOENT)
- r = journal_file_open("/run/log/journal/system.journal", O_RDONLY, 0644, &f);
-
+ r = sd_journal_open(&j);
if (r < 0) {
log_error("Failed to open journal: %s", strerror(-r));
if (r < 0) {
log_error("Failed to open journal: %s", strerror(-r));
-
return EXIT_FAILURE
;
+
goto finish
;
}
}
- for (;;) {
- uint64_t offset;
- uint64_t n, i;
-
- r = journal_file_next_entry(f, o, &o, &offset);
+ for (i = 1; i < argc; i++) {
+ r = sd_journal_add_match(j, argv[i], strlen(argv[i]));
if (r < 0) {
if (r < 0) {
- log_error("Failed to
read journal
: %s", strerror(-r));
+ log_error("Failed to
add match
: %s", strerror(-r));
goto finish;
}
goto finish;
}
+ }
- if (r == 0)
- break;
+ SD_JOURNAL_FOREACH_BEGIN(j) {
- printf("entry: %llu\n", (unsigned long long) le64toh(o->entry.seqnum));
+ const void *data;
+ size_t length;
+ char *cursor;
+ uint64_t realtime = 0, monotonic = 0;
- n = journal_file_entry_n_items(o);
- for (i = 0; i < n; i++) {
- uint64_t p, l;
+ r = sd_journal_get_cursor(j, &cursor);
+ if (r < 0) {
+ log_error("Failed to get cursor: %s", strerror(-r));
+ goto finish;
+ }
- p = le64toh(o->entry.items[i].object_offset);
- r = journal_file_move_to_object(f, p, &o);
- if (r < 0) {
- log_error("Failed to move to data: %s", strerror(-r));
- goto finish;
- }
+ printf("entry: %s\n", cursor);
+ free(cursor);
- if (le64toh(o->object.type) != OBJECT_DATA) {
- log_error("Invalid file");
- goto finish;
- }
+ sd_journal_get_realtime_usec(j, &realtime);
+ sd_journal_get_monotonic_usec(j, &monotonic);
+ printf("realtime: %llu\n"
+ "monotonic: %llu\n",
+ (unsigned long long) realtime,
+ (unsigned long long) monotonic);
- l = o->object.size - offsetof(Object, data.payload);
- printf("\t
[%.*s]\n", (int) l, o->data.payload
);
+ SD_JOURNAL_FOREACH_DATA(j, data, length)
+ printf("\t
%.*s\n", (int) length, (const char*) data
);
- r = journal_file_move_to_object(f, offset, &o);
- if (r < 0) {
- log_error("Failed to move back to entry: %s", strerror(-r));
- goto finish;
- }
- }
- }
+ } SD_JOURNAL_FOREACH_END(j);
finish:
finish:
- journal_file_close(f);
+ if (j)
+ sd_journal_close(j);
- return
0
;
+ return
r < 0 ? EXIT_FAILURE : EXIT_SUCCESS
;
}
}