chiark / gitweb /
journal: automaticall reset location when the set of matches changes
authorLennart Poettering <lennart@poettering.net>
Sat, 15 Oct 2011 00:53:04 +0000 (02:53 +0200)
committerLennart Poettering <lennart@poettering.net>
Sat, 15 Oct 2011 00:53:04 +0000 (02:53 +0200)
src/journal/sd-journal.c
src/journal/sd-journal.h

index 6a68275e9e3393765f3ed4d818826c6021e64af5..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,
@@ -708,25 +725,18 @@ void sd_journal_start_data(sd_journal *j) {
         j->current_field = 0;
 }
 
-static int real_journal_seek_head(sd_journal *j, direction_t direction) {
-        Iterator i;
-        JournalFile *f;
-
+int sd_journal_seek_head(sd_journal *j) {
         assert(j);
 
-        j->current_file = NULL;
-        j->current_field = 0;
-
-        HASHMAP_FOREACH(f, j->files, i)
-                f->current_offset = 0;
+        reset_location(j);
 
-        return real_journal_next(j, direction);
-}
-
-int sd_journal_seek_head(sd_journal *j) {
-        return real_journal_seek_head(j, DIRECTION_DOWN);
+        return real_journal_next(j, DIRECTION_DOWN);
 }
 
 int sd_journal_seek_tail(sd_journal *j) {
-        return real_journal_seek_head(j, DIRECTION_UP);
+        assert(j);
+
+        reset_location(j);
+
+        return real_journal_next(j, DIRECTION_UP);
 }
index bf6673453dbe31f9656c5c7c507b66abdf912f4a..9978ca9ac0dd2f500fbae691c6e87b843709d72b 100644 (file)
@@ -76,7 +76,7 @@ enum {
         SD_JOURNAL_DROP
 };
 
-int sd_journal_process(sd_journal *j);
+int sd_journal_process(sd_journal *j);                             /* missing */
 
 #define SD_JOURNAL_FOREACH_BEGIN(j)             \
         if (sd_journal_seek_head(j) > 0) do {