2 .TH "SD_JOURNAL_NEXT" "3" "" "systemd 217" "sd_journal_next"
3 .\" -----------------------------------------------------------------
4 .\" * Define some portability stuff
5 .\" -----------------------------------------------------------------
6 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 .\" http://bugs.debian.org/507673
8 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
9 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12 .\" -----------------------------------------------------------------
13 .\" * set default formatting
14 .\" -----------------------------------------------------------------
15 .\" disable hyphenation
17 .\" disable justification (adjust text to left margin only)
19 .\" -----------------------------------------------------------------
20 .\" * MAIN CONTENT STARTS HERE *
21 .\" -----------------------------------------------------------------
23 sd_journal_next, sd_journal_previous, sd_journal_next_skip, sd_journal_previous_skip, SD_JOURNAL_FOREACH, SD_JOURNAL_FOREACH_BACKWARDS \- Advance or set back the read pointer in the journal
28 #include <systemd/sd\-journal\&.h>
31 .HP \w'int\ sd_journal_next('u
32 .BI "int sd_journal_next(sd_journal\ *" "j" ");"
33 .HP \w'int\ sd_journal_previous('u
34 .BI "int sd_journal_previous(sd_journal\ *" "j" ");"
35 .HP \w'int\ sd_journal_next_skip('u
36 .BI "int sd_journal_next_skip(sd_journal\ *" "j" ", uint64_t\ " "skip" ");"
37 .HP \w'int\ sd_journal_previous_skip('u
38 .BI "int sd_journal_previous_skip(sd_journal\ *" "j" ", uint64_t\ " "skip" ");"
39 .HP \w'SD_JOURNAL_FOREACH('u
40 .BI "SD_JOURNAL_FOREACH(sd_journal\ *" "j" ");"
41 .HP \w'SD_JOURNAL_FOREACH_BACKWARDS('u
42 .BI "SD_JOURNAL_FOREACH_BACKWARDS(sd_journal\ *" "j" ");"
45 \fBsd_journal_next()\fR
46 advances the read pointer into the journal by one entry\&. The only argument taken is a journal context object as allocated via
47 \fBsd_journal_open\fR(3)\&. After successful invocation the entry may be read with functions such as
48 \fBsd_journal_get_data\fR(3)\&.
51 \fBsd_journal_previous()\fR
52 sets the read pointer back one entry\&.
54 \fBsd_journal_next_skip()\fR
56 \fBsd_journal_previous_skip()\fR
57 advance/set back the read pointer by multiple entries at once, as specified in the
61 The journal is strictly ordered by reception time, and hence advancing to the next entry guarantees that the entry then pointing to is later in time than then previous one, or has the same timestamp\&.
64 \fBsd_journal_get_data\fR(3)
65 and related calls will fail unless
66 \fBsd_journal_next()\fR
67 has been invoked at least once in order to position the read pointer on a journal entry\&.
70 \fBSD_JOURNAL_FOREACH()\fR
71 macro may be used as a wrapper around
72 \fBsd_journal_seek_head\fR(3)
74 \fBsd_journal_next()\fR
75 in order to make iterating through the journal easier\&. See below for an example\&. Similarly,
76 \fBSD_JOURNAL_FOREACH_BACKWARDS()\fR
77 may be used for iterating the journal in reverse order\&.
80 The four calls return the number of entries advanced/set back on success or a negative errno\-style error code\&. When the end or beginning of the journal is reached, a number smaller than requested is returned\&. More specifically, if
81 \fBsd_journal_next()\fR
83 \fBsd_journal_previous()\fR
84 reach the end/beginning of the journal they will return 0, instead of 1 when they are successful\&. This should be considered an EOF marker\&.
88 \fBsd_journal_next()\fR,
89 \fBsd_journal_previous()\fR,
90 \fBsd_journal_next_skip()\fR
92 \fBsd_journal_previous_skip()\fR
93 interfaces are available as a shared library, which can be compiled and linked to with the
94 \fBlibsystemd\fR\ \&\fBpkg-config\fR(1)
98 Iterating through the journal:
105 #include <string\&.h>
106 #include <systemd/sd\-journal\&.h>
108 int main(int argc, char *argv[]) {
111 r = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY);
113 fprintf(stderr, "Failed to open journal: %s\en", strerror(\-r));
116 SD_JOURNAL_FOREACH(j) {
120 r = sd_journal_get_data(j, "MESSAGE", (const void **)&d, &l);
122 fprintf(stderr, "Failed to read message field: %s\en", strerror(\-r));
126 printf("%\&.*s\en", (int) l, d);
139 \fBsd_journal_open\fR(3),
140 \fBsd_journal_get_data\fR(3),
141 \fBsd_journal_get_realtime_usec\fR(3),
142 \fBsd_journal_get_cursor\fR(3)