chiark / gitweb /
journal: implement seek to head/tail
[elogind.git] / src / journal / journalctl.c
index bb1f18a..3e5ee1a 100644 (file)
@@ -31,7 +31,7 @@
 #include "log.h"
 
 int main(int argc, char *argv[]) {
 #include "log.h"
 
 int main(int argc, char *argv[]) {
-        int r;
+        int r, i;
         sd_journal *j = NULL;
 
         log_set_max_level(LOG_DEBUG);
         sd_journal *j = NULL;
 
         log_set_max_level(LOG_DEBUG);
@@ -46,10 +46,20 @@ int main(int argc, char *argv[]) {
                 goto finish;
         }
 
                 goto finish;
         }
 
-        SD_JOURNAL_FOREACH(j) {
+        for (i = 1; i < argc; i++) {
+                r = sd_journal_add_match(j, argv[i], strlen(argv[i]));
+                if (r < 0) {
+                        log_error("Failed to add match: %s", strerror(-r));
+                        goto finish;
+                }
+        }
+
+        SD_JOURNAL_FOREACH_BEGIN(j) {
+
                 const void *data;
                 size_t length;
                 char *cursor;
                 const void *data;
                 size_t length;
                 char *cursor;
+                uint64_t realtime = 0, monotonic = 0;
 
                 r = sd_journal_get_cursor(j, &cursor);
                 if (r < 0) {
 
                 r = sd_journal_get_cursor(j, &cursor);
                 if (r < 0) {
@@ -60,9 +70,17 @@ int main(int argc, char *argv[]) {
                 printf("entry: %s\n", cursor);
                 free(cursor);
 
                 printf("entry: %s\n", cursor);
                 free(cursor);
 
-                SD_JOURNAL_FOREACH_FIELD(j, data, length)
+                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);
+
+                SD_JOURNAL_FOREACH_DATA(j, data, length)
                         printf("\t%.*s\n", (int) length, (const char*) data);
                         printf("\t%.*s\n", (int) length, (const char*) data);
-        }
+
+        } SD_JOURNAL_FOREACH_END(j);
 
 finish:
         if (j)
 
 finish:
         if (j)