mirror of
https://github.com/systemd/systemd.git
synced 2026-08-05 07:30:30 +00:00
journal: make return parameters for sd_journal_enumerate_unique() optional
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user