X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fjournal%2Fsd-journal.c;h=b9ec90230d74d0c9b7413594920ef328cfed7bb9;hb=1836bf9e1d70240c8079e4db4312309f4f1f91fd;hp=8dd82ec2ac30c985e8a07f9f8edcbe4118c05093;hpb=1ec7120e50bc084342f8c44aea771c79aaeb774d;p=elogind.git diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c index 8dd82ec2a..b9ec90230 100644 --- a/src/journal/sd-journal.c +++ b/src/journal/sd-journal.c @@ -997,7 +997,7 @@ _public_ int sd_journal_get_cursor(sd_journal *j, char **cursor) { } _public_ int sd_journal_seek_cursor(sd_journal *j, const char *cursor) { - char *w, *state; + const char *word, *state; size_t l; unsigned long long seqnum, monotonic, realtime, xor_hash; bool @@ -1013,18 +1013,18 @@ _public_ int sd_journal_seek_cursor(sd_journal *j, const char *cursor) { assert_return(!journal_pid_changed(j), -ECHILD); assert_return(!isempty(cursor), -EINVAL); - FOREACH_WORD_SEPARATOR(w, l, cursor, ";", state) { + FOREACH_WORD_SEPARATOR(word, l, cursor, ";", state) { char *item; int k = 0; - if (l < 2 || w[1] != '=') + if (l < 2 || word[1] != '=') return -EINVAL; - item = strndup(w, l); + item = strndup(word, l); if (!item) return -ENOMEM; - switch (w[0]) { + switch (word[0]) { case 's': seqnum_id_set = true; @@ -1103,7 +1103,7 @@ _public_ int sd_journal_seek_cursor(sd_journal *j, const char *cursor) { _public_ int sd_journal_test_cursor(sd_journal *j, const char *cursor) { int r; - char *w, *state; + const char *word, *state; size_t l; Object *o; @@ -1118,20 +1118,20 @@ _public_ int sd_journal_test_cursor(sd_journal *j, const char *cursor) { if (r < 0) return r; - FOREACH_WORD_SEPARATOR(w, l, cursor, ";", state) { + FOREACH_WORD_SEPARATOR(word, l, cursor, ";", state) { _cleanup_free_ char *item = NULL; sd_id128_t id; unsigned long long ll; int k = 0; - if (l < 2 || w[1] != '=') + if (l < 2 || word[1] != '=') return -EINVAL; - item = strndup(w, l); + item = strndup(word, l); if (!item) return -ENOMEM; - switch (w[0]) { + switch (word[0]) { case 's': k = sd_id128_from_string(item+2, &id); @@ -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; - - *data = f->compress_buffer; - *size = (size_t) rsize; + 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, '=')) { + + size_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; - 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) { - uint64_t rsize; +#if defined(HAVE_XZ) || defined(HAVE_LZ4) + size_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; @@ -2390,7 +2399,7 @@ _public_ int sd_journal_get_cutoff_realtime_usec(sd_journal *j, uint64_t *from, _public_ int sd_journal_get_cutoff_monotonic_usec(sd_journal *j, sd_id128_t boot_id, uint64_t *from, uint64_t *to) { Iterator i; JournalFile *f; - bool first = true; + bool found = false; int r; assert_return(j, -EINVAL); @@ -2409,21 +2418,21 @@ _public_ int sd_journal_get_cutoff_monotonic_usec(sd_journal *j, sd_id128_t boot if (r == 0) continue; - if (first) { + if (found) { if (from) - *from = fr; + *from = MIN(fr, *from); if (to) - *to = t; - first = false; + *to = MAX(t, *to); } else { if (from) - *from = MIN(fr, *from); + *from = fr; if (to) - *to = MAX(t, *to); + *to = t; + found = true; } } - return first ? 0 : 1; + return found; } void journal_print_header(sd_journal *j) {