SD_JOURNAL_SEEK_HEAD(3)
π SD_JOURNAL_SEEK_HEAD(3) β bestie's guide to seeking around the journal π
okay so this is the page for sd_journal_seek_head and its whole little friend group πΈ β they all live in the sd_journal_seek_head(3) manual, and they're literally the "teleport me to a spot in the journal" squad. no cap, they're icons.
β¨ NAME β¨
sd_journal_seek_head, sd_journal_seek_tail, sd_journal_seek_monotonic_usec, sd_journal_seek_realtime_usec, sd_journal_seek_cursor β seek to a position in the journal π―
π¦ SYNOPSIS π¦
#include <systemd/sd-journal.h>
int sd_journal_seek_head(sd_journal *j);
int sd_journal_seek_tail(sd_journal *j);
int sd_journal_seek_monotonic_usec(sd_journal *j, sd_id128_t boot_id,
uint64_t usec);
int sd_journal_seek_realtime_usec(sd_journal *j, uint64_t usec);
int sd_journal_seek_cursor(sd_journal *j, const char *cursor);
π DESCRIPTION π
okay so picture the journal as one giant timeline, right? these functions are how you yeet your little pointer to a specific spot on it. here's the tea, function by function:
sd_journal_seek_head()β seeks to the beginning of the journal. and by "beginning" i mean the position before the oldest available entry. like, you're standing just outside the door of the oldest thing. πͺsd_journal_seek_tail()β same energy, other end: seeks to the end of the journal, i.e. the position after the most recent available entry. you're past the newest thing, chilling. πsd_journal_seek_monotonic_usec()β seeks to the position with the specified monotonic timestamp, i.e.CLOCK_MONOTONIC. β±οΈ and because monotonic time restarts on every reboot, you literally have to hand over a boot ID too (boot_id). no boot ID, no vibes.sd_journal_seek_realtime_usec()β seeks to the position with the specified realtime (wallclock) timestamp, i.e.CLOCK_REALTIME. β° heads up though: the realtime clock is not necessarily monotonic. and if a realtime timestamp is ambiguous? it's not defined which position gets sought to. so likeβ¦ don't @ me. π«sd_journal_seek_cursor()β seeks to the position at the specified cursor string. for the deets on cursors, go seesd_journal_get_cursor(3). and if no entry matching the specified cursor is found, the call will seek to the next closest entry (in terms of time) instead. she improvises πββοΈ
β οΈ big thing, do not skip: these calls do not actually make any entry the new current entry. like, they move you to the address but don't open the door. you need a separate step β a subsequentsd_journal_next(3)invocation (or a similar call) β to actually land on an entry. only then can entry data be retrieved viasd_journal_get_data(3), or an entry cursor be retrieved viasd_journal_get_cursor(3).
and if no entry exists that matches exactly the specified seek address? the next closest one is sought to, bestie:
- if
sd_journal_next(3)is used, the closest following entry will be sought to β‘οΈ - if
sd_journal_previous(3)is used, the closest preceding entry is sought to β¬ οΈ
after the seek is done and sd_journal_next(3) or a similar call has been made, you can hit up sd_journal_test_cursor(3) to verify whether the newly selected entry actually matches the cursor. vibe check for entries, basically β
π RETURN VALUE π
the functions return 0 on success, or a negative errno-style error code. slay when zero, sad when negative π
π NOTES π
- all functions listed here are thread-agnostic β and only a single thread may operate on a given object at any given time. different threads may access the same object at different times. multiple independent objects may be used from different threads in parallel. so like, share the object politely, or just make more objects. π§
- functions described here are available as a shared library, which can be compiled against and linked to with the
libsystemdpkg-config(1)file. π
β HISTORY β
sd_journal_seek_head(), sd_journal_seek_tail(), sd_journal_seek_monotonic_usec(), sd_journal_seek_realtime_usec(), and sd_journal_seek_cursor() were added in version 187. vintage icons, honestly π
π₯ SEE ALSO π₯
systemd(1), sd-journal(3), sd_journal_open(3), sd_journal_next(3), sd_journal_get_data(3), sd_journal_get_cursor(3), sd_journal_get_realtime_usec(3)
that's the whole page, bestie π«Ά this cutie is from systemd 261.3, so go forth and seek responsibly πβ¨π
π¦ where this page comes from
- ubuntu stonking: libsystemd-dev 261.3-0ubuntu3 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms