]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/sd_journal_next.xml
man: be more explicit about thread safety of sd_journal
[thirdparty/systemd.git] / man / sd_journal_next.xml
CommitLineData
67c3cf4f
LP
1<?xml version='1.0'?> <!--*-nxml-*-->
2<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
12b42c76 3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
67c3cf4f
LP
4
5<!--
572eb058 6 SPDX-License-Identifier: LGPL-2.1+
67c3cf4f
LP
7-->
8
7d6b2723 9<refentry id="sd_journal_next" xmlns:xi="http://www.w3.org/2001/XInclude">
67c3cf4f 10
798d3a52
ZJS
11 <refentryinfo>
12 <title>sd_journal_next</title>
13 <productname>systemd</productname>
798d3a52
ZJS
14 </refentryinfo>
15
16 <refmeta>
17 <refentrytitle>sd_journal_next</refentrytitle>
18 <manvolnum>3</manvolnum>
19 </refmeta>
20
21 <refnamediv>
22 <refname>sd_journal_next</refname>
23 <refname>sd_journal_previous</refname>
24 <refname>sd_journal_next_skip</refname>
25 <refname>sd_journal_previous_skip</refname>
26 <refname>SD_JOURNAL_FOREACH</refname>
27 <refname>SD_JOURNAL_FOREACH_BACKWARDS</refname>
28 <refpurpose>Advance or set back the read pointer in the journal</refpurpose>
29 </refnamediv>
30
31 <refsynopsisdiv>
32 <funcsynopsis>
33 <funcsynopsisinfo>#include &lt;systemd/sd-journal.h&gt;</funcsynopsisinfo>
34
35 <funcprototype>
36 <funcdef>int <function>sd_journal_next</function></funcdef>
37 <paramdef>sd_journal *<parameter>j</parameter></paramdef>
38 </funcprototype>
39
40 <funcprototype>
41 <funcdef>int <function>sd_journal_previous</function></funcdef>
42 <paramdef>sd_journal *<parameter>j</parameter></paramdef>
43 </funcprototype>
44
45 <funcprototype>
46 <funcdef>int <function>sd_journal_next_skip</function></funcdef>
47 <paramdef>sd_journal *<parameter>j</parameter></paramdef>
48 <paramdef>uint64_t <parameter>skip</parameter></paramdef>
49 </funcprototype>
50
51 <funcprototype>
52 <funcdef>int <function>sd_journal_previous_skip</function></funcdef>
53 <paramdef>sd_journal *<parameter>j</parameter></paramdef>
54 <paramdef>uint64_t <parameter>skip</parameter></paramdef>
55 </funcprototype>
56
57 <funcprototype>
58 <funcdef><function>SD_JOURNAL_FOREACH</function></funcdef>
59 <paramdef>sd_journal *<parameter>j</parameter></paramdef>
60 </funcprototype>
61
62 <funcprototype>
63 <funcdef><function>SD_JOURNAL_FOREACH_BACKWARDS</function></funcdef>
64 <paramdef>sd_journal *<parameter>j</parameter></paramdef>
65 </funcprototype>
66 </funcsynopsis>
67 </refsynopsisdiv>
68
69 <refsect1>
70 <title>Description</title>
71
72 <para><function>sd_journal_next()</function> advances the read
73 pointer into the journal by one entry. The only argument taken is
74 a journal context object as allocated via
75 <citerefentry><refentrytitle>sd_journal_open</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
76 After successful invocation the entry may be read with functions
77 such as
78 <citerefentry><refentrytitle>sd_journal_get_data</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para>
79
80 <para>Similarly, <function>sd_journal_previous()</function> sets
81 the read pointer back one entry.</para>
82
83 <para><function>sd_journal_next_skip()</function> and
84 <function>sd_journal_previous_skip()</function> advance/set back
85 the read pointer by multiple entries at once, as specified in the
86 <varname>skip</varname> parameter.</para>
87
88 <para>The journal is strictly ordered by reception time, and hence
89 advancing to the next entry guarantees that the entry then
90 pointing to is later in time than then previous one, or has the
91 same timestamp.</para>
92
93 <para>Note that
94 <citerefentry><refentrytitle>sd_journal_get_data</refentrytitle><manvolnum>3</manvolnum></citerefentry>
95 and related calls will fail unless
96 <function>sd_journal_next()</function> has been invoked at least
97 once in order to position the read pointer on a journal
98 entry.</para>
99
100 <para>Note that the <function>SD_JOURNAL_FOREACH()</function>
101 macro may be used as a wrapper around
102 <citerefentry><refentrytitle>sd_journal_seek_head</refentrytitle><manvolnum>3</manvolnum></citerefentry>
103 and <function>sd_journal_next()</function> in order to make
104 iterating through the journal easier. See below for an example.
105 Similarly, <function>SD_JOURNAL_FOREACH_BACKWARDS()</function> may
106 be used for iterating the journal in reverse order.</para>
107 </refsect1>
108
109 <refsect1>
110 <title>Return Value</title>
111
112 <para>The four calls return the number of entries advanced/set
113 back on success or a negative errno-style error code. When the end
114 or beginning of the journal is reached, a number smaller than
115 requested is returned. More specifically, if
116 <function>sd_journal_next()</function> or
117 <function>sd_journal_previous()</function> reach the end/beginning
118 of the journal they will return 0, instead of 1 when they are
119 successful. This should be considered an EOF marker.</para>
120 </refsect1>
121
122 <refsect1>
123 <title>Notes</title>
124
64a7ef8b 125 <xi:include href="threads-aware.xml" xpointer="strict"/>
a8d46a16 126
7d6b2723 127 <xi:include href="libsystemd-pkgconfig.xml" xpointer="pkgconfig-text"/>
798d3a52
ZJS
128 </refsect1>
129
130 <refsect1>
131 <title>Examples</title>
132
133 <para>Iterating through the journal:</para>
134
135 <programlisting>#include &lt;stdio.h&gt;
67c3cf4f
LP
136#include &lt;string.h&gt;
137#include &lt;systemd/sd-journal.h&gt;
138
139int main(int argc, char *argv[]) {
798d3a52
ZJS
140 int r;
141 sd_journal *j;
142 r = sd_journal_open(&amp;j, SD_JOURNAL_LOCAL_ONLY);
143 if (r &lt; 0) {
144 fprintf(stderr, "Failed to open journal: %s\n", strerror(-r));
145 return 1;
146 }
147 SD_JOURNAL_FOREACH(j) {
148 const char *d;
149 size_t l;
150
151 r = sd_journal_get_data(j, "MESSAGE", (const void **)&amp;d, &amp;l);
152 if (r &lt; 0) {
153 fprintf(stderr, "Failed to read message field: %s\n", strerror(-r));
154 continue;
155 }
156
157 printf("%.*s\n", (int) l, d);
158 }
159 sd_journal_close(j);
160 return 0;
67c3cf4f
LP
161}</programlisting>
162
798d3a52 163 </refsect1>
67c3cf4f 164
798d3a52
ZJS
165 <refsect1>
166 <title>See Also</title>
67c3cf4f 167
798d3a52
ZJS
168 <para>
169 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
170 <citerefentry><refentrytitle>sd-journal</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
171 <citerefentry><refentrytitle>sd_journal_open</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
172 <citerefentry><refentrytitle>sd_journal_get_data</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
173 <citerefentry><refentrytitle>sd_journal_get_realtime_usec</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
174 <citerefentry><refentrytitle>sd_journal_get_cursor</refentrytitle><manvolnum>3</manvolnum></citerefentry>
175 </para>
176 </refsect1>
67c3cf4f
LP
177
178</refentry>