1 <?xml version='
1.0'
?> <!--*-nxml-*-->
2 <!DOCTYPE refentry PUBLIC
"-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
6 SPDX-License-Identifier: LGPL-2.1+
9 <refentry id=
"sd_journal_next" xmlns:
xi=
"http://www.w3.org/2001/XInclude">
12 <title>sd_journal_next
</title>
13 <productname>systemd
</productname>
17 <contrib>Developer
</contrib>
18 <firstname>Lennart
</firstname>
19 <surname>Poettering
</surname>
20 <email>lennart@poettering.net
</email>
26 <refentrytitle>sd_journal_next
</refentrytitle>
27 <manvolnum>3</manvolnum>
31 <refname>sd_journal_next
</refname>
32 <refname>sd_journal_previous
</refname>
33 <refname>sd_journal_next_skip
</refname>
34 <refname>sd_journal_previous_skip
</refname>
35 <refname>SD_JOURNAL_FOREACH
</refname>
36 <refname>SD_JOURNAL_FOREACH_BACKWARDS
</refname>
37 <refpurpose>Advance or set back the read pointer in the journal
</refpurpose>
42 <funcsynopsisinfo>#include
<systemd/sd-journal.h
></funcsynopsisinfo>
45 <funcdef>int
<function>sd_journal_next
</function></funcdef>
46 <paramdef>sd_journal *
<parameter>j
</parameter></paramdef>
50 <funcdef>int
<function>sd_journal_previous
</function></funcdef>
51 <paramdef>sd_journal *
<parameter>j
</parameter></paramdef>
55 <funcdef>int
<function>sd_journal_next_skip
</function></funcdef>
56 <paramdef>sd_journal *
<parameter>j
</parameter></paramdef>
57 <paramdef>uint64_t
<parameter>skip
</parameter></paramdef>
61 <funcdef>int
<function>sd_journal_previous_skip
</function></funcdef>
62 <paramdef>sd_journal *
<parameter>j
</parameter></paramdef>
63 <paramdef>uint64_t
<parameter>skip
</parameter></paramdef>
67 <funcdef><function>SD_JOURNAL_FOREACH
</function></funcdef>
68 <paramdef>sd_journal *
<parameter>j
</parameter></paramdef>
72 <funcdef><function>SD_JOURNAL_FOREACH_BACKWARDS
</function></funcdef>
73 <paramdef>sd_journal *
<parameter>j
</parameter></paramdef>
79 <title>Description
</title>
81 <para><function>sd_journal_next()
</function> advances the read
82 pointer into the journal by one entry. The only argument taken is
83 a journal context object as allocated via
84 <citerefentry><refentrytitle>sd_journal_open
</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
85 After successful invocation the entry may be read with functions
87 <citerefentry><refentrytitle>sd_journal_get_data
</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
</para>
89 <para>Similarly,
<function>sd_journal_previous()
</function> sets
90 the read pointer back one entry.
</para>
92 <para><function>sd_journal_next_skip()
</function> and
93 <function>sd_journal_previous_skip()
</function> advance/set back
94 the read pointer by multiple entries at once, as specified in the
95 <varname>skip
</varname> parameter.
</para>
97 <para>The journal is strictly ordered by reception time, and hence
98 advancing to the next entry guarantees that the entry then
99 pointing to is later in time than then previous one, or has the
100 same timestamp.
</para>
103 <citerefentry><refentrytitle>sd_journal_get_data
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
104 and related calls will fail unless
105 <function>sd_journal_next()
</function> has been invoked at least
106 once in order to position the read pointer on a journal
109 <para>Note that the
<function>SD_JOURNAL_FOREACH()
</function>
110 macro may be used as a wrapper around
111 <citerefentry><refentrytitle>sd_journal_seek_head
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
112 and
<function>sd_journal_next()
</function> in order to make
113 iterating through the journal easier. See below for an example.
114 Similarly,
<function>SD_JOURNAL_FOREACH_BACKWARDS()
</function> may
115 be used for iterating the journal in reverse order.
</para>
119 <title>Return Value
</title>
121 <para>The four calls return the number of entries advanced/set
122 back on success or a negative errno-style error code. When the end
123 or beginning of the journal is reached, a number smaller than
124 requested is returned. More specifically, if
125 <function>sd_journal_next()
</function> or
126 <function>sd_journal_previous()
</function> reach the end/beginning
127 of the journal they will return
0, instead of
1 when they are
128 successful. This should be considered an EOF marker.
</para>
134 <para>All functions listed here are thread-agnostic and only a single thread may operate
135 on a given
<structname>sd_journal
</structname> object.
</para>
137 <xi:include href=
"libsystemd-pkgconfig.xml" xpointer=
"pkgconfig-text"/>
141 <title>Examples
</title>
143 <para>Iterating through the journal:
</para>
145 <programlisting>#include
<stdio.h
>
146 #include
<string.h
>
147 #include
<systemd/sd-journal.h
>
149 int main(int argc, char *argv[]) {
152 r = sd_journal_open(
&j, SD_JOURNAL_LOCAL_ONLY);
154 fprintf(stderr,
"Failed to open journal: %s\n", strerror(-r));
157 SD_JOURNAL_FOREACH(j) {
161 r = sd_journal_get_data(j,
"MESSAGE", (const void **)
&d,
&l);
163 fprintf(stderr,
"Failed to read message field: %s\n", strerror(-r));
167 printf(
"%.*s\n", (int) l, d);
176 <title>See Also
</title>
179 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
180 <citerefentry><refentrytitle>sd-journal
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
181 <citerefentry><refentrytitle>sd_journal_open
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
182 <citerefentry><refentrytitle>sd_journal_get_data
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
183 <citerefentry><refentrytitle>sd_journal_get_realtime_usec
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
184 <citerefentry><refentrytitle>sd_journal_get_cursor
</refentrytitle><manvolnum>3</manvolnum></citerefentry>