summaryrefslogtreecommitdiff
path: root/src/journal/sd-journal.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-09-19 09:56:00 +0200
committerLennart Poettering <lennart@poettering.net>2012-09-19 09:58:34 +0200
commit468b21de7c9327bb8747d36e6273ed7aed97052a (patch)
tree3e52c52842fe5a4e2c01c0973579f54b7547585a /src/journal/sd-journal.c
parenta99124d92f8a60215f5ea5ed95de9792c1fb3324 (diff)
journal: when comparing two entries from separate files make sure we reposition the mmap window
The mmap cache doesn't guarantee that we can look at two files at the same time. Hence make sure to look at the entries to compare one after the other, instead of at the same time when comparing them, and reposition the window in between.
Diffstat (limited to 'src/journal/sd-journal.c')
-rw-r--r--src/journal/sd-journal.c44
1 files changed, 29 insertions, 15 deletions
diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c
index b4d35eebaf..2fa81727e0 100644
--- a/src/journal/sd-journal.c
+++ b/src/journal/sd-journal.c
@@ -357,15 +357,27 @@ _public_ void sd_journal_flush_matches(sd_journal *j) {
detach_location(j);
}
-static int compare_order(JournalFile *af, Object *ao,
- JournalFile *bf, Object *bo) {
+static int compare_entry_order(JournalFile *af, Object *_ao,
+ JournalFile *bf, uint64_t bp) {
uint64_t a, b;
+ Object *ao, *bo;
+ int r;
assert(af);
- assert(ao);
assert(bf);
- assert(bo);
+ assert(_ao);
+
+ /* The mmap cache might invalidate the object from the first
+ * file if we look at the one from the second file. Hence
+ * temporarily copy the header of the first one, and look at
+ * that only. */
+ ao = alloca(offsetof(EntryObject, items));
+ memcpy(ao, _ao, offsetof(EntryObject, items));
+
+ r = journal_file_move_to_object(bf, OBJECT_ENTRY, bp, &bo);
+ if (r < 0)
+ return strcmp(af->path, bf->path);
/* We operate on two different files here, hence we can access
* two objects at the same time, which we normally can't.
@@ -808,18 +820,17 @@ static int next_beyond_location(sd_journal *j, JournalFile *f, direction_t direc
}
static int real_journal_next(sd_journal *j, direction_t direction) {
- JournalFile *f, *new_current = NULL;
+ JournalFile *f, *new_file = NULL;
+ uint64_t new_offset = 0;
+ Object *o;
+ uint64_t p;
Iterator i;
int r;
- uint64_t new_offset = 0;
- Object *new_entry = NULL;
if (!j)
return -EINVAL;
HASHMAP_FOREACH(f, j->files, i) {
- Object *o;
- uint64_t p;
bool found;
r = next_beyond_location(j, f, direction, &o, &p);
@@ -829,12 +840,12 @@ static int real_journal_next(sd_journal *j, direction_t direction) {
} else if (r == 0)
continue;
- if (!new_current)
+ if (!new_file)
found = true;
else {
int k;
- k = compare_order(f, o, new_current, new_entry);
+ k = compare_entry_order(f, o, new_file, new_offset);
if (direction == DIRECTION_DOWN)
found = k < 0;
@@ -843,16 +854,19 @@ static int real_journal_next(sd_journal *j, direction_t direction) {
}
if (found) {
- new_current = f;
- new_entry = o;
+ new_file = f;
new_offset = p;
}
}
- if (!new_current)
+ if (!new_file)
return 0;
- set_location(j, new_current, new_entry, new_offset);
+ r = journal_file_move_to_object(new_file, OBJECT_ENTRY, new_offset, &o);
+ if (r < 0)
+ return r;
+
+ set_location(j, new_file, o, new_offset);
return 1;
}