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+
8 This file is part of systemd.
10 Copyright 2012 Lennart Poettering
13 <refentry id=
"sd_journal_next" xmlns:
xi=
"http://www.w3.org/2001/XInclude">
16 <title>sd_journal_next
</title>
17 <productname>systemd
</productname>
21 <contrib>Developer
</contrib>
22 <firstname>Lennart
</firstname>
23 <surname>Poettering
</surname>
24 <email>lennart@poettering.net
</email>
30 <refentrytitle>sd_journal_next
</refentrytitle>
31 <manvolnum>3</manvolnum>
35 <refname>sd_journal_next
</refname>
36 <refname>sd_journal_previous
</refname>
37 <refname>sd_journal_next_skip
</refname>
38 <refname>sd_journal_previous_skip
</refname>
39 <refname>SD_JOURNAL_FOREACH
</refname>
40 <refname>SD_JOURNAL_FOREACH_BACKWARDS
</refname>
41 <refpurpose>Advance or set back the read pointer in the journal
</refpurpose>
46 <funcsynopsisinfo>#include
<systemd/sd-journal.h
></funcsynopsisinfo>
49 <funcdef>int
<function>sd_journal_next
</function></funcdef>
50 <paramdef>sd_journal *
<parameter>j
</parameter></paramdef>
54 <funcdef>int
<function>sd_journal_previous
</function></funcdef>
55 <paramdef>sd_journal *
<parameter>j
</parameter></paramdef>
59 <funcdef>int
<function>sd_journal_next_skip
</function></funcdef>
60 <paramdef>sd_journal *
<parameter>j
</parameter></paramdef>
61 <paramdef>uint64_t
<parameter>skip
</parameter></paramdef>
65 <funcdef>int
<function>sd_journal_previous_skip
</function></funcdef>
66 <paramdef>sd_journal *
<parameter>j
</parameter></paramdef>
67 <paramdef>uint64_t
<parameter>skip
</parameter></paramdef>
71 <funcdef><function>SD_JOURNAL_FOREACH
</function></funcdef>
72 <paramdef>sd_journal *
<parameter>j
</parameter></paramdef>
76 <funcdef><function>SD_JOURNAL_FOREACH_BACKWARDS
</function></funcdef>
77 <paramdef>sd_journal *
<parameter>j
</parameter></paramdef>
83 <title>Description
</title>
85 <para><function>sd_journal_next()
</function> advances the read
86 pointer into the journal by one entry. The only argument taken is
87 a journal context object as allocated via
88 <citerefentry><refentrytitle>sd_journal_open
</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
89 After successful invocation the entry may be read with functions
91 <citerefentry><refentrytitle>sd_journal_get_data
</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
</para>
93 <para>Similarly,
<function>sd_journal_previous()
</function> sets
94 the read pointer back one entry.
</para>
96 <para><function>sd_journal_next_skip()
</function> and
97 <function>sd_journal_previous_skip()
</function> advance/set back
98 the read pointer by multiple entries at once, as specified in the
99 <varname>skip
</varname> parameter.
</para>
101 <para>The journal is strictly ordered by reception time, and hence
102 advancing to the next entry guarantees that the entry then
103 pointing to is later in time than then previous one, or has the
104 same timestamp.
</para>
107 <citerefentry><refentrytitle>sd_journal_get_data
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
108 and related calls will fail unless
109 <function>sd_journal_next()
</function> has been invoked at least
110 once in order to position the read pointer on a journal
113 <para>Note that the
<function>SD_JOURNAL_FOREACH()
</function>
114 macro may be used as a wrapper around
115 <citerefentry><refentrytitle>sd_journal_seek_head
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
116 and
<function>sd_journal_next()
</function> in order to make
117 iterating through the journal easier. See below for an example.
118 Similarly,
<function>SD_JOURNAL_FOREACH_BACKWARDS()
</function> may
119 be used for iterating the journal in reverse order.
</para>
123 <title>Return Value
</title>
125 <para>The four calls return the number of entries advanced/set
126 back on success or a negative errno-style error code. When the end
127 or beginning of the journal is reached, a number smaller than
128 requested is returned. More specifically, if
129 <function>sd_journal_next()
</function> or
130 <function>sd_journal_previous()
</function> reach the end/beginning
131 of the journal they will return
0, instead of
1 when they are
132 successful. This should be considered an EOF marker.
</para>
138 <para>All functions listed here are thread-agnostic and only a single thread may operate
139 on a given
<structname>sd_journal
</structname> object.
</para>
141 <xi:include href=
"libsystemd-pkgconfig.xml" xpointer=
"pkgconfig-text"/>
145 <title>Examples
</title>
147 <para>Iterating through the journal:
</para>
149 <programlisting>#include
<stdio.h
>
150 #include
<string.h
>
151 #include
<systemd/sd-journal.h
>
153 int main(int argc, char *argv[]) {
156 r = sd_journal_open(
&j, SD_JOURNAL_LOCAL_ONLY);
158 fprintf(stderr,
"Failed to open journal: %s\n", strerror(-r));
161 SD_JOURNAL_FOREACH(j) {
165 r = sd_journal_get_data(j,
"MESSAGE", (const void **)
&d,
&l);
167 fprintf(stderr,
"Failed to read message field: %s\n", strerror(-r));
171 printf(
"%.*s\n", (int) l, d);
180 <title>See Also
</title>
183 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
184 <citerefentry><refentrytitle>sd-journal
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
185 <citerefentry><refentrytitle>sd_journal_open
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
186 <citerefentry><refentrytitle>sd_journal_get_data
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
187 <citerefentry><refentrytitle>sd_journal_get_realtime_usec
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
188 <citerefentry><refentrytitle>sd_journal_get_cursor
</refentrytitle><manvolnum>3</manvolnum></citerefentry>