diff options
Diffstat (limited to 'src/journal')
-rw-r--r-- | src/journal/journal-verify.c | 39 | ||||
-rw-r--r-- | src/journal/sd-journal.c | 28 |
2 files changed, 27 insertions, 40 deletions
diff --git a/src/journal/journal-verify.c b/src/journal/journal-verify.c index c063d12210..5a0751f2aa 100644 --- a/src/journal/journal-verify.c +++ b/src/journal/journal-verify.c @@ -53,6 +53,7 @@ static int journal_file_object_verify(JournalFile *f, uint64_t offset, Object *o case OBJECT_DATA: { uint64_t h1, h2; + int compression, r; if (le64toh(o->data.entry_offset) == 0) log_warning(OFSfmt": unused data (entry_offset==0)", offset); @@ -72,40 +73,22 @@ static int journal_file_object_verify(JournalFile *f, uint64_t offset, Object *o h1 = le64toh(o->data.hash); - if (o->object.flags & OBJECT_COMPRESSED_XZ) { -#ifdef HAVE_XZ + compression = o->object.flags & OBJECT_COMPRESSION_MASK; + if (compression) { _cleanup_free_ void *b = NULL; uint64_t alloc = 0, b_size; - if (!decompress_blob_xz(o->data.payload, - le64toh(o->object.size) - offsetof(Object, data.payload), - &b, &alloc, &b_size, 0)) { - log_error(OFSfmt": XZ decompression failed", offset); - return -EBADMSG; - } - - h2 = hash64(b, b_size); -#else - log_error("XZ compression is not supported"); - return -EPROTONOSUPPORT; -#endif - } else if (o->object.flags & OBJECT_COMPRESSED_LZ4) { -#ifdef HAVE_XZ - _cleanup_free_ void *b = NULL; - uint64_t alloc = 0, b_size; - - if (!decompress_blob_xz(o->data.payload, - le64toh(o->object.size) - offsetof(Object, data.payload), - &b, &alloc, &b_size, 0)) { - log_error(OFSfmt": LZ4 decompression failed", offset); - return -EBADMSG; + r = decompress_blob(compression, + o->data.payload, + le64toh(o->object.size) - offsetof(Object, data.payload), + &b, &alloc, &b_size, 0); + if (r < 0) { + log_error(OFSfmt": %s decompression failed: %s", offset, + object_compressed_to_string(compression), strerror(-r)); + return r; } h2 = hash64(b, b_size); -#else - log_error("XZ compression is not supported"); - return -EPROTONOSUPPORT; -#endif } else h2 = hash64(o->data.payload, le64toh(o->object.size) - offsetof(Object, data.payload)); diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c index 96ba2bd11e..8dd82ec2ac 100644 --- a/src/journal/sd-journal.c +++ b/src/journal/sd-journal.c @@ -1983,6 +1983,7 @@ _public_ int sd_journal_get_data(sd_journal *j, const char *field, const void ** uint64_t p, l; le64_t le_hash; size_t t; + int compression; p = le64toh(o->entry.items[i].object_offset); le_hash = o->entry.items[i].hash; @@ -1995,17 +1996,19 @@ _public_ int sd_journal_get_data(sd_journal *j, const char *field, const void ** l = le64toh(o->object.size) - offsetof(Object, data.payload); - if ((o->object.flags & OBJECT_COMPRESSION_MASK) && - decompress_startswith(o->object.flags & OBJECT_COMPRESSION_MASK, + compression = o->object.flags & OBJECT_COMPRESSION_MASK; + if (compression && + decompress_startswith(compression, o->data.payload, l, &f->compress_buffer, &f->compress_buffer_size, field, field_length, '=')) { uint64_t rsize; - r = decompress_blob_xz(o->data.payload, l, - &f->compress_buffer, &f->compress_buffer_size, &rsize, - j->data_threshold); + r = decompress_blob(compression, + o->data.payload, l, + &f->compress_buffer, &f->compress_buffer_size, &rsize, + j->data_threshold); if (r < 0) return r; @@ -2040,6 +2043,7 @@ _public_ int sd_journal_get_data(sd_journal *j, const char *field, const void ** static int return_data(sd_journal *j, JournalFile *f, Object *o, const void **data, size_t *size) { size_t t; uint64_t l; + int compression, r; l = le64toh(o->object.size) - offsetof(Object, data.payload); t = (size_t) l; @@ -2048,18 +2052,18 @@ static int return_data(sd_journal *j, JournalFile *f, Object *o, const void **da if ((uint64_t) t != l) return -E2BIG; - if (o->object.flags & OBJECT_COMPRESSED_XZ) { -#ifdef HAVE_XZ + compression = o->object.flags & OBJECT_COMPRESSION_MASK; + if (compression) { uint64_t rsize; - if (!decompress_blob_xz(o->data.payload, l, &f->compress_buffer, &f->compress_buffer_size, &rsize, j->data_threshold)) - return -EBADMSG; + r = decompress_blob(compression, + o->data.payload, l, &f->compress_buffer, + &f->compress_buffer_size, &rsize, j->data_threshold); + if (r < 0) + return r; *data = f->compress_buffer; *size = (size_t) rsize; -#else - return -EPROTONOSUPPORT; -#endif } else { *data = o->data.payload; *size = t; |