]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/sd_journal_next.xml
Merge pull request #34 from systemd-mailing-devs/1432619328-32030-1-git-send-email...
[thirdparty/systemd.git] / man / sd_journal_next.xml
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" >
5 %entities;
6 ]>
7
8 <!--
9 This file is part of systemd.
10
11 Copyright 2012 Lennart Poettering
12
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.
17
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.
22
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/>.
25 -->
26
27 <refentry id="sd_journal_next">
28
29 <refentryinfo>
30 <title>sd_journal_next</title>
31 <productname>systemd</productname>
32
33 <authorgroup>
34 <author>
35 <contrib>Developer</contrib>
36 <firstname>Lennart</firstname>
37 <surname>Poettering</surname>
38 <email>lennart@poettering.net</email>
39 </author>
40 </authorgroup>
41 </refentryinfo>
42
43 <refmeta>
44 <refentrytitle>sd_journal_next</refentrytitle>
45 <manvolnum>3</manvolnum>
46 </refmeta>
47
48 <refnamediv>
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>
56 </refnamediv>
57
58 <refsynopsisdiv>
59 <funcsynopsis>
60 <funcsynopsisinfo>#include &lt;systemd/sd-journal.h&gt;</funcsynopsisinfo>
61
62 <funcprototype>
63 <funcdef>int <function>sd_journal_next</function></funcdef>
64 <paramdef>sd_journal *<parameter>j</parameter></paramdef>
65 </funcprototype>
66
67 <funcprototype>
68 <funcdef>int <function>sd_journal_previous</function></funcdef>
69 <paramdef>sd_journal *<parameter>j</parameter></paramdef>
70 </funcprototype>
71
72 <funcprototype>
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>
76 </funcprototype>
77
78 <funcprototype>
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>
82 </funcprototype>
83
84 <funcprototype>
85 <funcdef><function>SD_JOURNAL_FOREACH</function></funcdef>
86 <paramdef>sd_journal *<parameter>j</parameter></paramdef>
87 </funcprototype>
88
89 <funcprototype>
90 <funcdef><function>SD_JOURNAL_FOREACH_BACKWARDS</function></funcdef>
91 <paramdef>sd_journal *<parameter>j</parameter></paramdef>
92 </funcprototype>
93 </funcsynopsis>
94 </refsynopsisdiv>
95
96 <refsect1>
97 <title>Description</title>
98
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
104 such as
105 <citerefentry><refentrytitle>sd_journal_get_data</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para>
106
107 <para>Similarly, <function>sd_journal_previous()</function> sets
108 the read pointer back one entry.</para>
109
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>
114
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>
119
120 <para>Note that
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
125 entry.</para>
126
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>
134 </refsect1>
135
136 <refsect1>
137 <title>Return Value</title>
138
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>
147 </refsect1>
148
149 <refsect1>
150 <title>Notes</title>
151
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
157 with the
158 <constant>libsystemd</constant> <citerefentry project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
159 file.</para>
160 </refsect1>
161
162 <refsect1>
163 <title>Examples</title>
164
165 <para>Iterating through the journal:</para>
166
167 <programlisting>#include &lt;stdio.h&gt;
168 #include &lt;string.h&gt;
169 #include &lt;systemd/sd-journal.h&gt;
170
171 int main(int argc, char *argv[]) {
172 int r;
173 sd_journal *j;
174 r = sd_journal_open(&amp;j, SD_JOURNAL_LOCAL_ONLY);
175 if (r &lt; 0) {
176 fprintf(stderr, "Failed to open journal: %s\n", strerror(-r));
177 return 1;
178 }
179 SD_JOURNAL_FOREACH(j) {
180 const char *d;
181 size_t l;
182
183 r = sd_journal_get_data(j, "MESSAGE", (const void **)&amp;d, &amp;l);
184 if (r &lt; 0) {
185 fprintf(stderr, "Failed to read message field: %s\n", strerror(-r));
186 continue;
187 }
188
189 printf("%.*s\n", (int) l, d);
190 }
191 sd_journal_close(j);
192 return 0;
193 }</programlisting>
194
195 </refsect1>
196
197 <refsect1>
198 <title>See Also</title>
199
200 <para>
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>
207 </para>
208 </refsect1>
209
210 </refentry>