1
0
mirror of https://github.com/systemd/systemd.git synced 2025-06-02 17:07:47 +03:00

sd-journal: introduce two helper functions for adding filter

This commit is contained in:
Yu Watanabe 2024-03-22 04:43:31 +09:00
parent 9773f5860f
commit e21ad9c136
2 changed files with 34 additions and 0 deletions

View File

@ -140,6 +140,9 @@ char *journal_make_match_string(sd_journal *j);
void journal_print_header(sd_journal *j);
int journal_get_directories(sd_journal *j, char ***ret);
int journal_add_match_pair(sd_journal *j, const char *field, const char *value);
int journal_add_matchf(sd_journal *j, const char *format, ...) _printf_(2, 3);
#define JOURNAL_FOREACH_DATA_RETVAL(j, data, l, retval) \
for (sd_journal_restart_data(j); ((retval) = sd_journal_enumerate_data((j), &(data), &(l))) > 0; )

View File

@ -325,6 +325,37 @@ fail:
return -ENOMEM;
}
int journal_add_match_pair(sd_journal *j, const char *field, const char *value) {
_cleanup_free_ char *s = NULL;
assert(j);
assert(field);
assert(value);
s = strjoin(field, "=", value);
if (!s)
return -ENOMEM;
return sd_journal_add_match(j, s, 0);
}
int journal_add_matchf(sd_journal *j, const char *format, ...) {
_cleanup_free_ char *s = NULL;
va_list ap;
int r;
assert(j);
assert(format);
va_start(ap, format);
r = vasprintf(&s, format, ap);
va_end(ap);
if (r < 0)
return -ENOMEM;
return sd_journal_add_match(j, s, 0);
}
_public_ int sd_journal_add_conjunction(sd_journal *j) {
assert_return(j, -EINVAL);
assert_return(!journal_origin_changed(j), -ECHILD);