summaryrefslogtreecommitdiffstats
path: root/src/libsystemd/sd-journal
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2022-05-03 10:01:39 +0200
committerGitHub <noreply@github.com>2022-05-03 10:01:39 +0200
commit968680b23d1629d33deeea98b4f2b5fd106075b5 (patch)
tree31ea787585057be19cd6de4022d5c0566a44e2a2 /src/libsystemd/sd-journal
parentbuild(deps): bump github/super-linter from 4.9.1 to 4.9.2 (diff)
parentjournal: Document generic_array_bisect() (diff)
downloadsystemd-968680b23d1629d33deeea98b4f2b5fd106075b5.tar.xz
systemd-968680b23d1629d33deeea98b4f2b5fd106075b5.zip
Merge pull request #23135 from DaanDeMeyer/journal-move
journal: Only move to object if requested
Diffstat (limited to 'src/libsystemd/sd-journal')
-rw-r--r--src/libsystemd/sd-journal/journal-file.c13
-rw-r--r--src/libsystemd/sd-journal/sd-journal.c22
2 files changed, 23 insertions, 12 deletions
diff --git a/src/libsystemd/sd-journal/journal-file.c b/src/libsystemd/sd-journal/journal-file.c
index 2350220bf2..4292679b5f 100644
--- a/src/libsystemd/sd-journal/journal-file.c
+++ b/src/libsystemd/sd-journal/journal-file.c
@@ -2358,6 +2358,19 @@ static int generic_array_bisect(
uint64_t *ret_offset,
uint64_t *ret_idx) {
+ /* Given an entry array chain, this function finds the object "closest" to the given needle in the
+ * chain, taking into account the provided direction. A function can be provided to determine how
+ * an object is matched against the given needle.
+ *
+ * Given a journal file, the offset of an object and the needle, the test_object() function should
+ * return TEST_LEFT if the needle is located earlier in the entry array chain, TEST_RIGHT if the
+ * needle is located later in the entry array chain and TEST_FOUND if the object matches the needle.
+ * If test_object() returns TEST_FOUND for a specific object, that object's information will be used
+ * to populate the return values of this function. If test_object() never returns TEST_FOUND, the
+ * return values are populated with the details of one of the objects closest to the needle. If the
+ * direction is DIRECTION_UP, the earlier object is used. Otherwise, the later object is used.
+ */
+
uint64_t a, p, t = 0, i = 0, last_p = 0, last_index = UINT64_MAX;
bool subtract_one = false;
Object *array = NULL;
diff --git a/src/libsystemd/sd-journal/sd-journal.c b/src/libsystemd/sd-journal/sd-journal.c
index 80145c43e9..705a35de3f 100644
--- a/src/libsystemd/sd-journal/sd-journal.c
+++ b/src/libsystemd/sd-journal/sd-journal.c
@@ -493,7 +493,6 @@ static int next_for_match(
int r;
uint64_t np = 0;
- Object *n;
assert(j);
assert(m);
@@ -569,12 +568,12 @@ static int next_for_match(
assert(np > 0);
- r = journal_file_move_to_object(f, OBJECT_ENTRY, np, &n);
- if (r < 0)
- return r;
+ if (ret) {
+ r = journal_file_move_to_object(f, OBJECT_ENTRY, np, ret);
+ if (r < 0)
+ return r;
+ }
- if (ret)
- *ret = n;
if (offset)
*offset = np;
@@ -633,7 +632,6 @@ static int find_location_for_match(
} else if (m->type == MATCH_OR_TERM) {
uint64_t np = 0;
- Object *n;
/* Find the earliest match */
@@ -652,12 +650,12 @@ static int find_location_for_match(
if (np == 0)
return 0;
- r = journal_file_move_to_object(f, OBJECT_ENTRY, np, &n);
- if (r < 0)
- return r;
+ if (ret) {
+ r = journal_file_move_to_object(f, OBJECT_ENTRY, np, ret);
+ if (r < 0)
+ return r;
+ }
- if (ret)
- *ret = n;
if (offset)
*offset = np;