sd-journal: make sd_journal_get_data() output params optional

Allow callers to pass NULL for ret_data and/or ret_size when they only
need to check whether a field exists.  Initialize provided output
pointers to safe defaults and update the manual page accordingly.

Propagate the NULL-ness through to journal_file_data_payload() so that
downstream helpers can optimize for the existence-check case.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
noxiouz
2026-04-08 16:33:20 +02:00
committed by Zbigniew Jędrzejewski-Szmek
parent f8e88be1d1
commit 329233dcbf
2 changed files with 14 additions and 7 deletions
+6 -5
View File
@@ -2822,8 +2822,6 @@ _public_ int sd_journal_get_data(sd_journal *j, const char *field, const void **
assert_return(j, -EINVAL);
assert_return(!journal_origin_changed(j), -ECHILD);
assert_return(field, -EINVAL);
assert_return(ret_data, -EINVAL);
assert_return(ret_size, -EINVAL);
assert_return(field_is_valid(field), -EINVAL);
f = j->current_file;
@@ -2846,7 +2844,8 @@ _public_ int sd_journal_get_data(sd_journal *j, const char *field, const void **
size_t l;
p = journal_file_entry_item_object_offset(f, o, i);
r = journal_file_data_payload(f, NULL, p, field, field_length, j->data_threshold, &d, &l);
r = journal_file_data_payload(f, NULL, p, field, field_length, j->data_threshold,
ret_data ? &d : NULL, ret_size ? &l : NULL);
if (r == 0)
continue;
if (IN_SET(r, -EADDRNOTAVAIL, -EBADMSG)) {
@@ -2856,8 +2855,10 @@ _public_ int sd_journal_get_data(sd_journal *j, const char *field, const void **
if (r < 0)
return r;
*ret_data = d;
*ret_size = l;
if (ret_data)
*ret_data = d;
if (ret_size)
*ret_size = l;
return 0;
}