]>
Commit | Line | Data |
---|---|---|
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 <systemd/sd-journal.h></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 | ||
a8d46a16 ZJS |
125 | <para>All functions listed here are thread-agnostic and only a single thread may operate |
126 | on a given <structname>sd_journal</structname> object.</para> | |
127 | ||
7d6b2723 | 128 | <xi:include href="libsystemd-pkgconfig.xml" xpointer="pkgconfig-text"/> |
798d3a52 ZJS |
129 | </refsect1> |
130 | ||
131 | <refsect1> | |
132 | <title>Examples</title> | |
133 | ||
134 | <para>Iterating through the journal:</para> | |
135 | ||
136 | <programlisting>#include <stdio.h> | |
67c3cf4f LP |
137 | #include <string.h> |
138 | #include <systemd/sd-journal.h> | |
139 | ||
140 | int main(int argc, char *argv[]) { | |
798d3a52 ZJS |
141 | int r; |
142 | sd_journal *j; | |
143 | r = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY); | |
144 | if (r < 0) { | |
145 | fprintf(stderr, "Failed to open journal: %s\n", strerror(-r)); | |
146 | return 1; | |
147 | } | |
148 | SD_JOURNAL_FOREACH(j) { | |
149 | const char *d; | |
150 | size_t l; | |
151 | ||
152 | r = sd_journal_get_data(j, "MESSAGE", (const void **)&d, &l); | |
153 | if (r < 0) { | |
154 | fprintf(stderr, "Failed to read message field: %s\n", strerror(-r)); | |
155 | continue; | |
156 | } | |
157 | ||
158 | printf("%.*s\n", (int) l, d); | |
159 | } | |
160 | sd_journal_close(j); | |
161 | return 0; | |
67c3cf4f LP |
162 | }</programlisting> |
163 | ||
798d3a52 | 164 | </refsect1> |
67c3cf4f | 165 | |
798d3a52 ZJS |
166 | <refsect1> |
167 | <title>See Also</title> | |
67c3cf4f | 168 | |
798d3a52 ZJS |
169 | <para> |
170 | <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, | |
171 | <citerefentry><refentrytitle>sd-journal</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
172 | <citerefentry><refentrytitle>sd_journal_open</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
173 | <citerefentry><refentrytitle>sd_journal_get_data</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
174 | <citerefentry><refentrytitle>sd_journal_get_realtime_usec</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
175 | <citerefentry><refentrytitle>sd_journal_get_cursor</refentrytitle><manvolnum>3</manvolnum></citerefentry> | |
176 | </para> | |
177 | </refsect1> | |
67c3cf4f LP |
178 | |
179 | </refentry> |