]> err.no Git - systemd/commitdiff
journal: move field index from file into journal object
authorLennart Poettering <lennart@poettering.net>
Fri, 14 Oct 2011 03:38:40 +0000 (05:38 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 14 Oct 2011 03:38:40 +0000 (05:38 +0200)
src/journal/journal-file.h
src/journal/sd-journal.c

index 92f671a756833e6bf950b04b3a238daf45c1886c..0294555cab023242eeedf7c452d8eef0d6f6ae00 100644 (file)
@@ -52,7 +52,6 @@ typedef struct JournalFile {
         uint64_t window_size;
 
         uint64_t current_offset;
-        uint64_t current_field;
 } JournalFile;
 
 int journal_file_open(const char *fname, int flags, mode_t mode, JournalFile *template, JournalFile **ret);
index 35f911f2ba8e8000b50b29473a6f2a9204571a3c..74abac88af74ad262d4649518fea1e8109ca570d 100644 (file)
@@ -43,6 +43,7 @@ struct sd_journal {
         Hashmap *files;
 
         JournalFile *current_file;
+        uint64_t current_field;
 
         LIST_HEAD(Match, matches);
 };
@@ -177,7 +178,7 @@ int sd_journal_next(sd_journal *j) {
         if (new_current) {
                 j->current_file = new_current;
                 j->current_file->current_offset = new_offset;
-                j->current_file->current_field = 0;
+                j->current_field = 0;
 
                 /* Skip over any identical entries in the other files too */
 
@@ -201,10 +202,8 @@ int sd_journal_next(sd_journal *j) {
                         else if (r == 0)
                                 continue;
 
-                        if (compare_order(new_current, new_entry, new_offset, f, o, p) == 0) {
+                        if (compare_order(new_current, new_entry, new_offset, f, o, p) == 0)
                                 f->current_offset = p;
-                                f->current_field = 0;
-                        }
                 }
 
                 return 1;
@@ -249,7 +248,34 @@ int sd_journal_previous(sd_journal *j) {
         if (new_current) {
                 j->current_file = new_current;
                 j->current_file->current_offset = new_offset;
-                j->current_file->current_field = 0;
+                j->current_field = 0;
+
+                /* Skip over any identical entries in the other files too */
+
+                HASHMAP_FOREACH(f, j->files, i) {
+                        Object *o;
+                        uint64_t p;
+
+                        if (j->current_file == f)
+                                continue;
+
+                        if (f->current_offset > 0) {
+                                r = journal_file_move_to_object(f, f->current_offset, OBJECT_ENTRY, &o);
+                                if (r < 0)
+                                        return r;
+                        } else
+                                o = NULL;
+
+                        r = journal_file_prev_entry(f, o, &o, &p);
+                        if (r < 0)
+                                return r;
+                        else if (r == 0)
+                                continue;
+
+                        if (compare_order(new_current, new_entry, new_offset, f, o, p) == 0)
+                                f->current_offset = p;
+                }
+
                 return 1;
         }
 
@@ -592,10 +618,10 @@ int sd_journal_iterate_fields(sd_journal *j, const void **data, size_t *size) {
                 return r;
 
         n = journal_file_entry_n_items(o);
-        if (f->current_field >= n)
+        if (j->current_field >= n)
                 return 0;
 
-        p = le64toh(o->entry.items[f->current_field].object_offset);
+        p = le64toh(o->entry.items[j->current_field].object_offset);
         r = journal_file_move_to_object(f, p, OBJECT_DATA, &o);
         if (r < 0)
                 return r;
@@ -610,7 +636,7 @@ int sd_journal_iterate_fields(sd_journal *j, const void **data, size_t *size) {
         *data = o->data.payload;
         *size = t;
 
-        f->current_field ++;
+        j->current_field ++;
 
         return 1;
 }