1SD_JOURNAL_NEXT(3)              sd_journal_next             SD_JOURNAL_NEXT(3)
2
3
4

NAME

6       sd_journal_next, sd_journal_previous, sd_journal_next_skip,
7       sd_journal_previous_skip, SD_JOURNAL_FOREACH,
8       SD_JOURNAL_FOREACH_BACKWARDS - Advance or set back the read pointer in
9       the journal
10

SYNOPSIS

12       #include <systemd/sd-journal.h>
13
14       int sd_journal_next(sd_journal *j);
15
16       int sd_journal_previous(sd_journal *j);
17
18       int sd_journal_next_skip(sd_journal *j, uint64_t skip);
19
20       int sd_journal_previous_skip(sd_journal *j, uint64_t skip);
21
22       SD_JOURNAL_FOREACH(sd_journal *j);
23
24       SD_JOURNAL_FOREACH_BACKWARDS(sd_journal *j);
25

DESCRIPTION

27       sd_journal_next() advances the read pointer into the journal by one
28       entry. The only argument taken is a journal context object as allocated
29       via sd_journal_open(3). After successful invocation the entry may be
30       read with functions such as sd_journal_get_data(3).
31
32       Similarly, sd_journal_previous() sets the read pointer back one entry.
33
34       sd_journal_next_skip() and sd_journal_previous_skip() advance/set back
35       the read pointer by multiple entries at once, as specified in the skip
36       parameter.
37
38       The journal is strictly ordered by reception time, and hence advancing
39       to the next entry guarantees that the entry then pointing to is later
40       in time than then previous one, or has the same timestamp.
41
42       Note that sd_journal_get_data(3) and related calls will fail unless
43       sd_journal_next() has been invoked at least once in order to position
44       the read pointer on a journal entry.
45
46       Note that the SD_JOURNAL_FOREACH() macro may be used as a wrapper
47       around sd_journal_seek_head(3) and sd_journal_next() in order to make
48       iterating through the journal easier. See below for an example.
49       Similarly, SD_JOURNAL_FOREACH_BACKWARDS() may be used for iterating the
50       journal in reverse order.
51

RETURN VALUE

53       The four calls return the number of entries advanced/set back on
54       success or a negative errno-style error code. When the end or beginning
55       of the journal is reached, a number smaller than requested is returned.
56       More specifically, if sd_journal_next() or sd_journal_previous() reach
57       the end/beginning of the journal they will return 0, instead of 1 when
58       they are successful. This should be considered an EOF marker.
59

NOTES

61       All functions listed here are thread-agnostic and only a single thread
62       may operate on a given sd_journal object.
63
64       These APIs are implemented as a shared library, which can be compiled
65       and linked to with the libsystemd pkg-config(1) file.
66

EXAMPLES

68       Iterating through the journal:
69
70           #include <stdio.h>
71           #include <string.h>
72           #include <systemd/sd-journal.h>
73
74           int main(int argc, char *argv[]) {
75             int r;
76             sd_journal *j;
77             r = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY);
78             if (r < 0) {
79               fprintf(stderr, "Failed to open journal: %s\n", strerror(-r));
80               return 1;
81             }
82             SD_JOURNAL_FOREACH(j) {
83               const char *d;
84               size_t l;
85
86               r = sd_journal_get_data(j, "MESSAGE", (const void **)&d, &l);
87               if (r < 0) {
88                 fprintf(stderr, "Failed to read message field: %s\n", strerror(-r));
89                 continue;
90               }
91
92               printf("%.*s\n", (int) l, d);
93             }
94             sd_journal_close(j);
95             return 0;
96           }
97

SEE ALSO

99       systemd(1), sd-journal(3), sd_journal_open(3), sd_journal_get_data(3),
100       sd_journal_get_realtime_usec(3), sd_journal_get_cursor(3)
101
102
103
104systemd 239                                                 SD_JOURNAL_NEXT(3)
Impressum