chiark / gitweb /
journal: automaticall reset location when the set of matches changes
[elogind.git] / src / journal / sd-journal.c
index 985e3210ce20fd16108bb81ebae4de842f56b996..5d518a38709d07c2d1b9e7903f940a13838c90fb 100644 (file)
@@ -50,6 +50,19 @@ struct sd_journal {
         unsigned n_matches;
 };
 
+static void reset_location(sd_journal *j) {
+        Iterator i;
+        JournalFile *f;
+
+        assert(j);
+
+        j->current_file = NULL;
+        j->current_field = 0;
+
+        HASHMAP_FOREACH(f, j->files, i)
+                f->current_offset = 0;
+}
+
 int sd_journal_add_match(sd_journal *j, const void *data, size_t size) {
         Match *m;
 
@@ -78,6 +91,8 @@ int sd_journal_add_match(sd_journal *j, const void *data, size_t size) {
         LIST_PREPEND(Match, matches, j->matches, m);
         j->n_matches ++;
 
+        reset_location(j);
+
         return 0;
 }
 
@@ -93,6 +108,8 @@ void sd_journal_flush_matches(sd_journal *j) {
         }
 
         j->n_matches = 0;
+
+        reset_location(j);
 }
 
 static int compare_order(JournalFile *af, Object *ao, uint64_t ap,
@@ -585,7 +602,7 @@ int sd_journal_get_monotonic_usec(sd_journal *j, uint64_t *ret) {
 
 }
 
-int sd_journal_get_field(sd_journal *j, const char *field, const void **data, size_t *size) {
+int sd_journal_get_data(sd_journal *j, const char *field, const void **data, size_t *size) {
         JournalFile *f;
         uint64_t i, n;
         size_t field_length;
@@ -652,7 +669,7 @@ int sd_journal_get_field(sd_journal *j, const char *field, const void **data, si
         return 0;
 }
 
-int sd_journal_iterate_fields(sd_journal *j, const void **data, size_t *size) {
+int sd_journal_enumerate_data(sd_journal *j, const void **data, size_t *size) {
         JournalFile *f;
         uint64_t p, l, n, h;
         size_t t;
@@ -702,12 +719,24 @@ int sd_journal_iterate_fields(sd_journal *j, const void **data, size_t *size) {
         return 1;
 }
 
+void sd_journal_start_data(sd_journal *j) {
+        assert(j);
+
+        j->current_field = 0;
+}
+
 int sd_journal_seek_head(sd_journal *j) {
         assert(j);
-        return -EINVAL;
+
+        reset_location(j);
+
+        return real_journal_next(j, DIRECTION_DOWN);
 }
 
 int sd_journal_seek_tail(sd_journal *j) {
         assert(j);
-        return -EINVAL;
+
+        reset_location(j);
+
+        return real_journal_next(j, DIRECTION_UP);
 }