[systemd-devel] [PATCH] journal: fix LZ4 and XZ decompression
Ronny Chevalier
chevalier.ronny at gmail.com
Mon Jul 7 01:04:34 PDT 2014
LZ4 was not always properly supported and a typo would have made the build failed
---
src/journal/journal-def.h | 2 +-
src/journal/journal-file.c | 2 +-
src/journal/journal-verify.c | 6 +++---
src/journal/sd-journal.c | 21 +++++++++++----------
src/journal/test-compress.c | 2 +-
5 files changed, 17 insertions(+), 16 deletions(-)
diff --git a/src/journal/journal-def.h b/src/journal/journal-def.h
index ecfa9a2..089dd98 100644
--- a/src/journal/journal-def.h
+++ b/src/journal/journal-def.h
@@ -180,7 +180,7 @@ enum {
};
#define HEADER_COMPATIBLE_ANY HEADER_COMPATIBLE_SEALED
-#if HAVE_GCRYPT
+#ifdef HAVE_GCRYPT
# define HEADER_COMPATIBLE_SUPPORTED HEADER_COMPATIBLE_SEALED
#else
# define HEADER_COMPATIBLE_SUPPORTED 0
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
index b6de502..d3535d2 100644
--- a/src/journal/journal-file.c
+++ b/src/journal/journal-file.c
@@ -2476,7 +2476,7 @@ int journal_file_open(
f->flags = flags;
f->prot = prot_from_flags(flags);
f->writable = (flags & O_ACCMODE) != O_RDONLY;
-#if defined(HAVE_LZ)
+#if defined(HAVE_LZ4)
f->compress_lz4 = compress;
#elif defined(HAVE_XZ)
f->compress_xz = compress;
diff --git a/src/journal/journal-verify.c b/src/journal/journal-verify.c
index c063d12..63fbc01 100644
--- a/src/journal/journal-verify.c
+++ b/src/journal/journal-verify.c
@@ -90,11 +90,11 @@ static int journal_file_object_verify(JournalFile *f, uint64_t offset, Object *o
return -EPROTONOSUPPORT;
#endif
} else if (o->object.flags & OBJECT_COMPRESSED_LZ4) {
-#ifdef HAVE_XZ
+#ifdef HAVE_LZ4
_cleanup_free_ void *b = NULL;
uint64_t alloc = 0, b_size;
- if (!decompress_blob_xz(o->data.payload,
+ if (!decompress_blob_lz4(o->data.payload,
le64toh(o->object.size) - offsetof(Object, data.payload),
&b, &alloc, &b_size, 0)) {
log_error(OFSfmt": LZ4 decompression failed", offset);
@@ -103,7 +103,7 @@ static int journal_file_object_verify(JournalFile *f, uint64_t offset, Object *o
h2 = hash64(b, b_size);
#else
- log_error("XZ compression is not supported");
+ log_error("LZ4 compression is not supported");
return -EPROTONOSUPPORT;
#endif
} else
diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c
index 96ba2bd..f55750a 100644
--- a/src/journal/sd-journal.c
+++ b/src/journal/sd-journal.c
@@ -2003,9 +2003,10 @@ _public_ int sd_journal_get_data(sd_journal *j, const char *field, const void **
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(o->object.flags & OBJECT_COMPRESSION_MASK,
+ o->data.payload, l,
+ &f->compress_buffer, &f->compress_buffer_size, &rsize,
+ j->data_threshold);
if (r < 0)
return r;
@@ -2048,18 +2049,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
+ if (o->object.flags & OBJECT_COMPRESSION_MASK) {
uint64_t rsize;
+ int r;
- if (!decompress_blob_xz(o->data.payload, l, &f->compress_buffer, &f->compress_buffer_size, &rsize, j->data_threshold))
- return -EBADMSG;
+ r = decompress_blob(o->object.flags & OBJECT_COMPRESSION_MASK,
+ 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;
diff --git a/src/journal/test-compress.c b/src/journal/test-compress.c
index 6ac8373..4c0a9a0 100644
--- a/src/journal/test-compress.c
+++ b/src/journal/test-compress.c
@@ -27,7 +27,7 @@
# define XZ_OK -EPROTONOSUPPORT
#endif
-#ifdef HAVE_XZ
+#ifdef HAVE_LZ4
# define LZ4_OK 0
#else
# define LZ4_OK -EPROTONOSUPPORT
--
2.0.1
More information about the systemd-devel
mailing list