]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/sd_journal_next.xml
Reindent man pages to 2ch
[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
5 <!--
6 This file is part of systemd.
7
8 Copyright 2012 Lennart Poettering
9
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 -->
23
24 <refentry id="sd_journal_next">
25
26 <refentryinfo>
27 <title>sd_journal_next</title>
28 <productname>systemd</productname>
29
30 <authorgroup>
31 <author>
32 <contrib>Developer</contrib>
33 <firstname>Lennart</firstname>
34 <surname>Poettering</surname>
35 <email>lennart@poettering.net</email>
36 </author>
37 </authorgroup>
38 </refentryinfo>
39
40 <refmeta>
41 <refentrytitle>sd_journal_next</refentrytitle>
42 <manvolnum>3</manvolnum>
43 </refmeta>
44
45 <refnamediv>
46 <refname>sd_journal_next</refname>
47 <refname>sd_journal_previous</refname>
48 <refname>sd_journal_next_skip</refname>
49 <refname>sd_journal_previous_skip</refname>
50 <refname>SD_JOURNAL_FOREACH</refname>
51 <refname>SD_JOURNAL_FOREACH_BACKWARDS</refname>
52 <refpurpose>Advance or set back the read pointer in the journal</refpurpose>
53 </refnamediv>
54
55 <refsynopsisdiv>
56 <funcsynopsis>
57 <funcsynopsisinfo>#include &lt;systemd/sd-journal.h&gt;</funcsynopsisinfo>
58
59 <funcprototype>
60 <funcdef>int <function>sd_journal_next</function></funcdef>
61 <paramdef>sd_journal *<parameter>j</parameter></paramdef>
62 </funcprototype>
63
64 <funcprototype>
65 <funcdef>int <function>sd_journal_previous</function></funcdef>
66 <paramdef>sd_journal *<parameter>j</parameter></paramdef>
67 </funcprototype>
68
69 <funcprototype>
70 <funcdef>int <function>sd_journal_next_skip</function></funcdef>
71 <paramdef>sd_journal *<parameter>j</parameter></paramdef>
72 <paramdef>uint64_t <parameter>skip</parameter></paramdef>
73 </funcprototype>
74
75 <funcprototype>
76 <funcdef>int <function>sd_journal_previous_skip</function></funcdef>
77 <paramdef>sd_journal *<parameter>j</parameter></paramdef>
78 <paramdef>uint64_t <parameter>skip</parameter></paramdef>
79 </funcprototype>
80
81 <funcprototype>
82 <funcdef><function>SD_JOURNAL_FOREACH</function></funcdef>
83 <paramdef>sd_journal *<parameter>j</parameter></paramdef>
84 </funcprototype>
85
86 <funcprototype>
87 <funcdef><function>SD_JOURNAL_FOREACH_BACKWARDS</function></funcdef>
88 <paramdef>sd_journal *<parameter>j</parameter></paramdef>
89 </funcprototype>
90 </funcsynopsis>
91 </refsynopsisdiv>
92
93 <refsect1>
94 <title>Description</title>
95
96 <para><function>sd_journal_next()</function> advances the read
97 pointer into the journal by one entry. The only argument taken is
98 a journal context object as allocated via
99 <citerefentry><refentrytitle>sd_journal_open</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
100 After successful invocation the entry may be read with functions
101 such as
102 <citerefentry><refentrytitle>sd_journal_get_data</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para>
103
104 <para>Similarly, <function>sd_journal_previous()</function> sets
105 the read pointer back one entry.</para>
106
107 <para><function>sd_journal_next_skip()</function> and
108 <function>sd_journal_previous_skip()</function> advance/set back
109 the read pointer by multiple entries at once, as specified in the
110 <varname>skip</varname> parameter.</para>
111
112 <para>The journal is strictly ordered by reception time, and hence
113 advancing to the next entry guarantees that the entry then
114 pointing to is later in time than then previous one, or has the
115 same timestamp.</para>
116
117 <para>Note that
118 <citerefentry><refentrytitle>sd_journal_get_data</refentrytitle><manvolnum>3</manvolnum></citerefentry>
119 and related calls will fail unless
120 <function>sd_journal_next()</function> has been invoked at least
121 once in order to position the read pointer on a journal
122 entry.</para>
123
124 <para>Note that the <function>SD_JOURNAL_FOREACH()</function>
125 macro may be used as a wrapper around
126 <citerefentry><refentrytitle>sd_journal_seek_head</refentrytitle><manvolnum>3</manvolnum></citerefentry>
127 and <function>sd_journal_next()</function> in order to make
128 iterating through the journal easier. See below for an example.
129 Similarly, <function>SD_JOURNAL_FOREACH_BACKWARDS()</function> may
130 be used for iterating the journal in reverse order.</para>
131 </refsect1>
132
133 <refsect1>
134 <title>Return Value</title>
135
136 <para>The four calls return the number of entries advanced/set
137 back on success or a negative errno-style error code. When the end
138 or beginning of the journal is reached, a number smaller than
139 requested is returned. More specifically, if
140 <function>sd_journal_next()</function> or
141 <function>sd_journal_previous()</function> reach the end/beginning
142 of the journal they will return 0, instead of 1 when they are
143 successful. This should be considered an EOF marker.</para>
144 </refsect1>
145
146 <refsect1>
147 <title>Notes</title>
148
149 <para>The <function>sd_journal_next()</function>,
150 <function>sd_journal_previous()</function>,
151 <function>sd_journal_next_skip()</function> and
152 <function>sd_journal_previous_skip()</function> interfaces are
153 available as a shared library, which can be compiled and linked to
154 with the
155 <constant>libsystemd</constant> <citerefentry project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
156 file.</para>
157 </refsect1>
158
159 <refsect1>
160 <title>Examples</title>
161
162 <para>Iterating through the journal:</para>
163
164 <programlisting>#include &lt;stdio.h&gt;
165 #include &lt;string.h&gt;
166 #include &lt;systemd/sd-journal.h&gt;
167
168 int main(int argc, char *argv[]) {
169 int r;
170 sd_journal *j;
171 r = sd_journal_open(&amp;j, SD_JOURNAL_LOCAL_ONLY);
172 if (r &lt; 0) {
173 fprintf(stderr, "Failed to open journal: %s\n", strerror(-r));
174 return 1;
175 }
176 SD_JOURNAL_FOREACH(j) {
177 const char *d;
178 size_t l;
179
180 r = sd_journal_get_data(j, "MESSAGE", (const void **)&amp;d, &amp;l);
181 if (r &lt; 0) {
182 fprintf(stderr, "Failed to read message field: %s\n", strerror(-r));
183 continue;
184 }
185
186 printf("%.*s\n", (int) l, d);
187 }
188 sd_journal_close(j);
189 return 0;
190 }</programlisting>
191
192 </refsect1>
193
194 <refsect1>
195 <title>See Also</title>
196
197 <para>
198 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
199 <citerefentry><refentrytitle>sd-journal</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
200 <citerefentry><refentrytitle>sd_journal_open</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
201 <citerefentry><refentrytitle>sd_journal_get_data</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
202 <citerefentry><refentrytitle>sd_journal_get_realtime_usec</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
203 <citerefentry><refentrytitle>sd_journal_get_cursor</refentrytitle><manvolnum>3</manvolnum></citerefentry>
204 </para>
205 </refsect1>
206
207 </refentry>