X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;ds=sidebyside;f=src%2Fjournal%2Fjournal-file.c;h=4de1daf6a0b177bed7105fc32ea493cc8da4a95c;hb=fd8ee359a014916ac62ae2b58f6736ccb48c6d4e;hp=45aab0e54a0eacfb2b3923a6c1ae2c8e50e66f0f;hpb=6c8a39b883d77a1e04f2947a2e890dfb8dd51d04;p=elogind.git diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c index 45aab0e54..4de1daf6a 100644 --- a/src/journal/journal-file.c +++ b/src/journal/journal-file.c @@ -138,6 +138,9 @@ static int journal_file_refresh_header(JournalFile *f) { f->header->boot_id = boot_id; f->header->state = STATE_ONLINE; + + __sync_synchronize(); + return 0; } @@ -293,6 +296,15 @@ static int journal_file_move_to(JournalFile *f, int wt, uint64_t offset, uint64_ assert(wt >= 0); assert(wt < _WINDOW_MAX); + if (offset + size > (uint64_t) f->last_stat.st_size) { + /* Hmm, out of range? Let's refresh the fstat() data + * first, before we trust that check. */ + + if (fstat(f->fd, &f->last_stat) < 0 || + offset + size > (uint64_t) f->last_stat.st_size) + return -EADDRNOTAVAIL; + } + w = f->windows + wt; if (_likely_(w->ptr && @@ -320,17 +332,14 @@ static int journal_file_move_to(JournalFile *f, int wt, uint64_t offset, uint64_ delta = PAGE_ALIGN((DEFAULT_WINDOW_SIZE - size) / 2); - if (offset < delta) + if (delta > offset) delta = offset; offset -= delta; - size += (DEFAULT_WINDOW_SIZE - delta); + size = DEFAULT_WINDOW_SIZE; } else delta = 0; - if (offset > (uint64_t) f->last_stat.st_size) - return -EADDRNOTAVAIL; - if (offset + size > (uint64_t) f->last_stat.st_size) size = PAGE_ALIGN((uint64_t) f->last_stat.st_size - offset); @@ -898,6 +907,8 @@ static int journal_file_link_entry(JournalFile *f, Object *o, uint64_t offset) { assert(offset > 0); assert(o->object.type == OBJECT_ENTRY); + __sync_synchronize(); + /* Link up the entry itself */ r = link_entry_into_array(f, &f->header->entry_array_offset, @@ -1005,9 +1016,6 @@ int journal_file_append_entry(JournalFile *f, const dual_timestamp *ts, const st ts->monotonic < le64toh(f->header->tail_entry_monotonic)) return -EINVAL; - if (ts->realtime < le64toh(f->header->tail_entry_realtime)) - return -EINVAL; - items = alloca(sizeof(EntryItem) * n_iovec); for (i = 0; i < n_iovec; i++) {