From: Lennart Poettering Date: Tue, 8 Jun 2021 21:15:04 +0000 (+0200) Subject: journal: make return parameters for sd_journal_enumerate_unique() optional X-Git-Tag: v249-rc1~53^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0e0b05294b3eee39966ee36b1ec72ea0c170cab2;p=thirdparty%2Fsystemd.git journal: make return parameters for sd_journal_enumerate_unique() optional --- diff --git a/src/libsystemd/sd-journal/sd-journal.c b/src/libsystemd/sd-journal/sd-journal.c index 4d101f02c8e..0a79d8c98d5 100644 --- a/src/libsystemd/sd-journal/sd-journal.c +++ b/src/libsystemd/sd-journal/sd-journal.c @@ -2368,18 +2368,27 @@ _public_ int sd_journal_get_data(sd_journal *j, const char *field, const void ** return -ENOENT; } -static int return_data(sd_journal *j, JournalFile *f, Object *o, const void **data, size_t *size) { +static int return_data( + sd_journal *j, + JournalFile *f, + Object *o, + const void **ret_data, + size_t *ret_size) { + size_t t; uint64_t l; int compression; + assert(j); + assert(f); + l = le64toh(READ_NOW(o->object.size)); if (l < offsetof(Object, data.payload)) return -EBADMSG; l -= offsetof(Object, data.payload); - t = (size_t) l; /* We can't read objects larger than 4G on a 32bit machine */ + t = (size_t) l; if ((uint64_t) t != l) return -E2BIG; @@ -2397,14 +2406,18 @@ static int return_data(sd_journal *j, JournalFile *f, Object *o, const void **da if (r < 0) return r; - *data = f->compress_buffer; - *size = (size_t) rsize; + if (ret_data) + *ret_data = f->compress_buffer; + if (ret_size) + *ret_size = (size_t) rsize; #else return -EPROTONOSUPPORT; #endif } else { - *data = o->data.payload; - *size = t; + if (ret_data) + *ret_data = o->data.payload; + if (ret_size) + *ret_size = t; } return 0; @@ -2891,13 +2904,15 @@ _public_ int sd_journal_query_unique(sd_journal *j, const char *field) { return 0; } -_public_ int sd_journal_enumerate_unique(sd_journal *j, const void **data, size_t *l) { +_public_ int sd_journal_enumerate_unique( + sd_journal *j, + const void **ret_data, + size_t *ret_size) { + size_t k; assert_return(j, -EINVAL); assert_return(!journal_pid_changed(j), -ECHILD); - assert_return(data, -EINVAL); - assert_return(l, -EINVAL); assert_return(j->unique_field, -EINVAL); k = strlen(j->unique_field); @@ -2971,16 +2986,15 @@ _public_ int sd_journal_enumerate_unique(sd_journal *j, const void **data, size_ j->unique_file->path, j->unique_offset, ol, k + 1); - if (memcmp(odata, j->unique_field, k) || ((const char*) odata)[k] != '=') + if (memcmp(odata, j->unique_field, k) != 0 || ((const char*) odata)[k] != '=') return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG), "%s:offset " OFSfmt ": object does not start with \"%s=\"", j->unique_file->path, j->unique_offset, j->unique_field); - /* OK, now let's see if we already returned this data - * object by checking if it exists in the earlier - * traversed files. */ + /* OK, now let's see if we already returned this data object by checking if it exists in the + * earlier traversed files. */ found = false; ORDERED_HASHMAP_FOREACH(of, j->files) { if (of == j->unique_file) @@ -3002,7 +3016,7 @@ _public_ int sd_journal_enumerate_unique(sd_journal *j, const void **data, size_ if (found) continue; - r = return_data(j, j->unique_file, o, data, l); + r = return_data(j, j->unique_file, o, ret_data, ret_size); if (r < 0) return r;