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" [
4 <!ENTITY % entities SYSTEM
"custom-entities.ent" >
9 This file is part of systemd.
11 Copyright 2012 Lennart Poettering
13 systemd is free software; you can redistribute it and/or modify it
14 under the terms of the GNU Lesser General Public License as published by
15 the Free Software Foundation; either version 2.1 of the License, or
16 (at your option) any later version.
18 systemd is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 Lesser General Public License for more details.
23 You should have received a copy of the GNU Lesser General Public License
24 along with systemd; If not, see <http://www.gnu.org/licenses/>.
27 <refentry id=
"sd_journal_next">
30 <title>sd_journal_next
</title>
31 <productname>systemd
</productname>
35 <contrib>Developer
</contrib>
36 <firstname>Lennart
</firstname>
37 <surname>Poettering
</surname>
38 <email>lennart@poettering.net
</email>
44 <refentrytitle>sd_journal_next
</refentrytitle>
45 <manvolnum>3</manvolnum>
49 <refname>sd_journal_next
</refname>
50 <refname>sd_journal_previous
</refname>
51 <refname>sd_journal_next_skip
</refname>
52 <refname>sd_journal_previous_skip
</refname>
53 <refname>SD_JOURNAL_FOREACH
</refname>
54 <refname>SD_JOURNAL_FOREACH_BACKWARDS
</refname>
55 <refpurpose>Advance or set back the read pointer in the journal
</refpurpose>
60 <funcsynopsisinfo>#include
<systemd/sd-journal.h
></funcsynopsisinfo>
63 <funcdef>int
<function>sd_journal_next
</function></funcdef>
64 <paramdef>sd_journal *
<parameter>j
</parameter></paramdef>
68 <funcdef>int
<function>sd_journal_previous
</function></funcdef>
69 <paramdef>sd_journal *
<parameter>j
</parameter></paramdef>
73 <funcdef>int
<function>sd_journal_next_skip
</function></funcdef>
74 <paramdef>sd_journal *
<parameter>j
</parameter></paramdef>
75 <paramdef>uint64_t
<parameter>skip
</parameter></paramdef>
79 <funcdef>int
<function>sd_journal_previous_skip
</function></funcdef>
80 <paramdef>sd_journal *
<parameter>j
</parameter></paramdef>
81 <paramdef>uint64_t
<parameter>skip
</parameter></paramdef>
85 <funcdef><function>SD_JOURNAL_FOREACH
</function></funcdef>
86 <paramdef>sd_journal *
<parameter>j
</parameter></paramdef>
90 <funcdef><function>SD_JOURNAL_FOREACH_BACKWARDS
</function></funcdef>
91 <paramdef>sd_journal *
<parameter>j
</parameter></paramdef>
97 <title>Description
</title>
99 <para><function>sd_journal_next()
</function> advances the read
100 pointer into the journal by one entry. The only argument taken is
101 a journal context object as allocated via
102 <citerefentry><refentrytitle>sd_journal_open
</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
103 After successful invocation the entry may be read with functions
105 <citerefentry><refentrytitle>sd_journal_get_data
</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
</para>
107 <para>Similarly,
<function>sd_journal_previous()
</function> sets
108 the read pointer back one entry.
</para>
110 <para><function>sd_journal_next_skip()
</function> and
111 <function>sd_journal_previous_skip()
</function> advance/set back
112 the read pointer by multiple entries at once, as specified in the
113 <varname>skip
</varname> parameter.
</para>
115 <para>The journal is strictly ordered by reception time, and hence
116 advancing to the next entry guarantees that the entry then
117 pointing to is later in time than then previous one, or has the
118 same timestamp.
</para>
121 <citerefentry><refentrytitle>sd_journal_get_data
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
122 and related calls will fail unless
123 <function>sd_journal_next()
</function> has been invoked at least
124 once in order to position the read pointer on a journal
127 <para>Note that the
<function>SD_JOURNAL_FOREACH()
</function>
128 macro may be used as a wrapper around
129 <citerefentry><refentrytitle>sd_journal_seek_head
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
130 and
<function>sd_journal_next()
</function> in order to make
131 iterating through the journal easier. See below for an example.
132 Similarly,
<function>SD_JOURNAL_FOREACH_BACKWARDS()
</function> may
133 be used for iterating the journal in reverse order.
</para>
137 <title>Return Value
</title>
139 <para>The four calls return the number of entries advanced/set
140 back on success or a negative errno-style error code. When the end
141 or beginning of the journal is reached, a number smaller than
142 requested is returned. More specifically, if
143 <function>sd_journal_next()
</function> or
144 <function>sd_journal_previous()
</function> reach the end/beginning
145 of the journal they will return
0, instead of
1 when they are
146 successful. This should be considered an EOF marker.
</para>
152 <para>The
<function>sd_journal_next()
</function>,
153 <function>sd_journal_previous()
</function>,
154 <function>sd_journal_next_skip()
</function> and
155 <function>sd_journal_previous_skip()
</function> interfaces are
156 available as a shared library, which can be compiled and linked to
158 <constant>libsystemd
</constant> <citerefentry project='die-net'
><refentrytitle>pkg-config
</refentrytitle><manvolnum>1</manvolnum></citerefentry>
163 <title>Examples
</title>
165 <para>Iterating through the journal:
</para>
167 <programlisting>#include
<stdio.h
>
168 #include
<string.h
>
169 #include
<systemd/sd-journal.h
>
171 int main(int argc, char *argv[]) {
174 r = sd_journal_open(
&j, SD_JOURNAL_LOCAL_ONLY);
176 fprintf(stderr,
"Failed to open journal: %s\n", strerror(-r));
179 SD_JOURNAL_FOREACH(j) {
183 r = sd_journal_get_data(j,
"MESSAGE", (const void **)
&d,
&l);
185 fprintf(stderr,
"Failed to read message field: %s\n", strerror(-r));
189 printf(
"%.*s\n", (int) l, d);
198 <title>See Also
</title>
201 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
202 <citerefentry><refentrytitle>sd-journal
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
203 <citerefentry><refentrytitle>sd_journal_open
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
204 <citerefentry><refentrytitle>sd_journal_get_data
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
205 <citerefentry><refentrytitle>sd_journal_get_realtime_usec
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
206 <citerefentry><refentrytitle>sd_journal_get_cursor
</refentrytitle><manvolnum>3</manvolnum></citerefentry>