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       The sd_journal_next(), sd_journal_previous(), sd_journal_next_skip()
62       and sd_journal_previous_skip() interfaces are available as a shared
63       library, which can be compiled and linked to with the libsystemd pkg-
64       config(1) file.
65

EXAMPLES

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

SEE ALSO

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