summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2023-01-12 17:48:43 +0100
committerLennart Poettering <lennart@poettering.net>2023-02-08 13:42:29 +0100
commitb1712fabd1702640b04b0acdbba2d78294313a4d (patch)
tree95dc0163fec4b26dfe719e725caafce29b7cb99e
parent11c0f0659ecd82572c2dc83f3b34493a36dcd954 (diff)
downloadsystemd-b1712fabd1702640b04b0acdbba2d78294313a4d.tar.gz
sd-journal: add high-level API for querying seqnum for journal entries, along with seqnum id
-rw-r--r--src/libsystemd/libsystemd.sym1
-rw-r--r--src/libsystemd/sd-journal/sd-journal.c31
-rw-r--r--src/systemd/sd-journal.h1
3 files changed, 33 insertions, 0 deletions
diff --git a/src/libsystemd/libsystemd.sym b/src/libsystemd/libsystemd.sym
index 0f2230a42f..802009b710 100644
--- a/src/libsystemd/libsystemd.sym
+++ b/src/libsystemd/libsystemd.sym
@@ -810,4 +810,5 @@ global:
sd_pidfd_get_unit;
sd_pidfd_get_user_slice;
sd_pidfd_get_user_unit;
+ sd_journal_get_seqnum;
} LIBSYSTEMD_252;
diff --git a/src/libsystemd/sd-journal/sd-journal.c b/src/libsystemd/sd-journal/sd-journal.c
index 659e1e4e34..61249816a4 100644
--- a/src/libsystemd/sd-journal/sd-journal.c
+++ b/src/libsystemd/sd-journal/sd-journal.c
@@ -2228,6 +2228,37 @@ _public_ int sd_journal_get_monotonic_usec(sd_journal *j, uint64_t *ret, sd_id12
return 0;
}
+_public_ int sd_journal_get_seqnum(
+ sd_journal *j,
+ uint64_t *ret_seqnum,
+ sd_id128_t *ret_seqnum_id) {
+
+ JournalFile *f;
+ Object *o;
+ int r;
+
+ assert_return(j, -EINVAL);
+ assert_return(!journal_pid_changed(j), -ECHILD);
+
+ f = j->current_file;
+ if (!f)
+ return -EADDRNOTAVAIL;
+
+ if (f->current_offset <= 0)
+ return -EADDRNOTAVAIL;
+
+ r = journal_file_move_to_object(f, OBJECT_ENTRY, f->current_offset, &o);
+ if (r < 0)
+ return r;
+
+ if (ret_seqnum_id)
+ *ret_seqnum_id = f->header->seqnum_id;
+ if (ret_seqnum)
+ *ret_seqnum = le64toh(o->entry.seqnum);
+
+ return 0;
+}
+
static bool field_is_valid(const char *field) {
assert(field);
diff --git a/src/systemd/sd-journal.h b/src/systemd/sd-journal.h
index 24638f1e0a..24e67663b9 100644
--- a/src/systemd/sd-journal.h
+++ b/src/systemd/sd-journal.h
@@ -99,6 +99,7 @@ int sd_journal_next_skip(sd_journal *j, uint64_t skip);
int sd_journal_get_realtime_usec(sd_journal *j, uint64_t *ret);
int sd_journal_get_monotonic_usec(sd_journal *j, uint64_t *ret, sd_id128_t *ret_boot_id);
+int sd_journal_get_seqnum(sd_journal *j, uint64_t *ret_seqnum, sd_id128_t *ret_seqnum_id);
int sd_journal_set_data_threshold(sd_journal *j, size_t sz);
int sd_journal_get_data_threshold(sd_journal *j, size_t *sz);