X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fjournal%2Fjournal-file.c;h=59ad84e23b0eb54d31cd992410f4ae1555f6ffbf;hb=9058851be7821edac08c1fa7ecafe5cba9ab9022;hp=15a752d507eae8892e92ae7931dd3d562347a28c;hpb=b788cc23aa50682fe80c1b78cc5e42aaf7d76bc5;p=elogind.git diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c index 15a752d50..59ad84e23 100644 --- a/src/journal/journal-file.c +++ b/src/journal/journal-file.c @@ -296,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 && @@ -321,21 +330,18 @@ static int journal_file_move_to(JournalFile *f, int wt, uint64_t offset, uint64_ * the window space before and half behind the * requested mapping */ - delta = PAGE_ALIGN((DEFAULT_WINDOW_SIZE - size) / 2); + delta = (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); + size = (uint64_t) f->last_stat.st_size - offset; if (size <= 0) return -EADDRNOTAVAIL; @@ -911,7 +917,7 @@ static int journal_file_link_entry(JournalFile *f, Object *o, uint64_t offset) { if (r < 0) return r; - log_error("=> %s seqnr=%lu n_entries=%lu", f->path, (unsigned long) o->entry.seqnum, (unsigned long) f->header->n_entries); + /* log_debug("=> %s seqnr=%lu n_entries=%lu", f->path, (unsigned long) o->entry.seqnum, (unsigned long) f->header->n_entries); */ if (f->header->head_entry_realtime == 0) f->header->head_entry_realtime = o->entry.realtime; @@ -1010,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++) { @@ -2100,7 +2103,7 @@ int journal_file_copy_entry(JournalFile *from, JournalFile *to, Object *o, uint6 void journal_default_metrics(JournalMetrics *m, int fd) { uint64_t fs_size = 0; struct statvfs ss; - char a[64], b[64], c[64], d[64]; + char a[FORMAT_BYTES_MAX], b[FORMAT_BYTES_MAX], c[FORMAT_BYTES_MAX], d[FORMAT_BYTES_MAX]; assert(m); assert(fd >= 0);