From 3b1a55e110ab387a8d213581983e20c0a63d7894 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 11 Jul 2014 10:42:06 -0400 Subject: [PATCH] Fix build without any compression enabled --- Makefile.am | 2 ++ configure.ac | 2 ++ src/journal/compress.c | 4 ++++ src/journal/coredump.c | 2 +- src/journal/journal-file.c | 9 +++++++- src/journal/sd-journal.c | 47 +++++++++++++++++++++++--------------- 6 files changed, 45 insertions(+), 21 deletions(-) diff --git a/Makefile.am b/Makefile.am index f934bb147..bb8fc475b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -3667,9 +3667,11 @@ tests += \ test-mmap-cache \ test-catalog +if HAVE_COMPRESSION tests += \ test-compress \ test-compress-benchmark +endif pkginclude_HEADERS += \ src/systemd/sd-journal.h \ diff --git a/configure.ac b/configure.ac index 19af217a2..e16d50d4c 100644 --- a/configure.ac +++ b/configure.ac @@ -520,6 +520,8 @@ AS_IF([test "x$enable_lz4" == "xyes"], [ ]) AM_CONDITIONAL(HAVE_LZ4, [test "$have_lz4" = "yes"]) +AM_CONDITIONAL(HAVE_COMPRESSION, [test "$have_xz" = "yes" -o "$have_lz4" = "yes"]) + # ------------------------------------------------------------------------------ AC_ARG_ENABLE([pam], AS_HELP_STRING([--disable-pam],[Disable optional PAM support]), diff --git a/src/journal/compress.c b/src/journal/compress.c index 93ac92aaa..316c1a66e 100644 --- a/src/journal/compress.c +++ b/src/journal/compress.c @@ -343,6 +343,7 @@ int decompress_startswith(int compression, } int compress_stream_xz(int fdf, int fdt, off_t max_bytes) { +#ifdef HAVE_XZ _cleanup_(lzma_end) lzma_stream s = LZMA_STREAM_INIT; lzma_ret ret; @@ -414,6 +415,9 @@ int compress_stream_xz(int fdf, int fdt, off_t max_bytes) { } } } +#else + return -EPROTONOSUPPORT; +#endif } #define LZ4_BUFSIZE (512*1024) diff --git a/src/journal/coredump.c b/src/journal/coredump.c index 59c6d4b71..1b8c2e8bc 100644 --- a/src/journal/coredump.c +++ b/src/journal/coredump.c @@ -402,9 +402,9 @@ static int save_external_coredump( fail_compressed: unlink_noerrno(tmp_compressed); } -#endif uncompressed: +#endif r = fix_permissions(fd, tmp, fn, info, uid); if (r < 0) goto fail; diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c index d3535d2fa..dc041dd58 100644 --- a/src/journal/journal-file.c +++ b/src/journal/journal-file.c @@ -819,6 +819,7 @@ int journal_file_find_data_object_with_hash( goto next; if (o->object.flags & OBJECT_COMPRESSION_MASK) { +#if defined(HAVE_XZ) || defined(HAVE_LZ4) uint64_t l, rsize; l = le64toh(o->object.size); @@ -843,7 +844,9 @@ int journal_file_find_data_object_with_hash( return 1; } - +#else + return -EPROTONOSUPPORT; +#endif } else if (le64toh(o->object.size) == osize && memcmp(o->data.payload, data, size) == 0) { @@ -2772,6 +2775,7 @@ int journal_file_copy_entry(JournalFile *from, JournalFile *to, Object *o, uint6 return -E2BIG; if (o->object.flags & OBJECT_COMPRESSION_MASK) { +#if defined(HAVE_XZ) || defined(HAVE_LZ4) uint64_t rsize; r = decompress_blob(o->object.flags & OBJECT_COMPRESSION_MASK, @@ -2781,6 +2785,9 @@ int journal_file_copy_entry(JournalFile *from, JournalFile *to, Object *o, uint6 data = from->compress_buffer; l = rsize; +#else + return -EPROTONOSUPPORT; +#endif } else data = o->data.payload; diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c index 8dd82ec2a..f674abf9d 100644 --- a/src/journal/sd-journal.c +++ b/src/journal/sd-journal.c @@ -1997,26 +1997,30 @@ _public_ int sd_journal_get_data(sd_journal *j, const char *field, const void ** l = le64toh(o->object.size) - offsetof(Object, data.payload); 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(compression, - o->data.payload, l, - &f->compress_buffer, &f->compress_buffer_size, &rsize, - j->data_threshold); - if (r < 0) - return r; + if (compression) { +#if defined(HAVE_XZ) || defined(HAVE_LZ4) + if (decompress_startswith(compression, + o->data.payload, l, + &f->compress_buffer, &f->compress_buffer_size, + field, field_length, '=')) { + + uint64_t rsize; + + 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; - - return 0; + *data = f->compress_buffer; + *size = (size_t) rsize; + return 0; + } +#else + return -EPROTONOSUPPORT; +#endif } else if (l >= field_length+1 && memcmp(o->data.payload, field, field_length) == 0 && o->data.payload[field_length] == '=') { @@ -2043,7 +2047,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; + int compression; l = le64toh(o->object.size) - offsetof(Object, data.payload); t = (size_t) l; @@ -2054,7 +2058,9 @@ static int return_data(sd_journal *j, JournalFile *f, Object *o, const void **da compression = o->object.flags & OBJECT_COMPRESSION_MASK; if (compression) { +#if defined(HAVE_XZ) || defined(HAVE_LZ4) uint64_t rsize; + int r; r = decompress_blob(compression, o->data.payload, l, &f->compress_buffer, @@ -2064,6 +2070,9 @@ static int return_data(sd_journal *j, JournalFile *f, Object *o, const void **da *data = f->compress_buffer; *size = (size_t) rsize; +#else + return -EPROTONOSUPPORT; +#endif } else { *data = o->data.payload; *size = t; -- 2.30.2