]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/sd_journal_get_data.xml
travis: add more ASan options
[thirdparty/systemd.git] / man / sd_journal_get_data.xml
CommitLineData
4171a667 1<?xml version='1.0'?> <!--*-nxml-*-->
3a54a157 2<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
12b42c76 3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
0307f791 4<!-- SPDX-License-Identifier: LGPL-2.1+ -->
4171a667 5
7d6b2723 6<refentry id="sd_journal_get_data" xmlns:xi="http://www.w3.org/2001/XInclude">
4171a667 7
798d3a52
ZJS
8 <refentryinfo>
9 <title>sd_journal_get_data</title>
10 <productname>systemd</productname>
798d3a52
ZJS
11 </refentryinfo>
12
13 <refmeta>
14 <refentrytitle>sd_journal_get_data</refentrytitle>
15 <manvolnum>3</manvolnum>
16 </refmeta>
17
18 <refnamediv>
19 <refname>sd_journal_get_data</refname>
20 <refname>sd_journal_enumerate_data</refname>
21 <refname>sd_journal_restart_data</refname>
22 <refname>SD_JOURNAL_FOREACH_DATA</refname>
23 <refname>sd_journal_set_data_threshold</refname>
24 <refname>sd_journal_get_data_threshold</refname>
25 <refpurpose>Read data fields from the current journal entry</refpurpose>
26 </refnamediv>
27
28 <refsynopsisdiv>
29 <funcsynopsis>
30 <funcsynopsisinfo>#include &lt;systemd/sd-journal.h&gt;</funcsynopsisinfo>
31
32 <funcprototype>
33 <funcdef>int <function>sd_journal_get_data</function></funcdef>
34 <paramdef>sd_journal *<parameter>j</parameter></paramdef>
35 <paramdef>const char *<parameter>field</parameter></paramdef>
36 <paramdef>const void **<parameter>data</parameter></paramdef>
37 <paramdef>size_t *<parameter>length</parameter></paramdef>
38 </funcprototype>
39
40 <funcprototype>
41 <funcdef>int <function>sd_journal_enumerate_data</function></funcdef>
42 <paramdef>sd_journal *<parameter>j</parameter></paramdef>
43 <paramdef>const void **<parameter>data</parameter></paramdef>
44 <paramdef>size_t *<parameter>length</parameter></paramdef>
45 </funcprototype>
46
47 <funcprototype>
48 <funcdef>void <function>sd_journal_restart_data</function></funcdef>
49 <paramdef>sd_journal *<parameter>j</parameter></paramdef>
50 </funcprototype>
51
52 <funcprototype>
53 <funcdef><function>SD_JOURNAL_FOREACH_DATA</function></funcdef>
54 <paramdef>sd_journal *<parameter>j</parameter></paramdef>
55 <paramdef>const void *<parameter>data</parameter></paramdef>
56 <paramdef>size_t <parameter>length</parameter></paramdef>
57 </funcprototype>
58
59 <funcprototype>
60 <funcdef>int <function>sd_journal_set_data_threshold</function></funcdef>
61 <paramdef>sd_journal *<parameter>j</parameter></paramdef>
62 <paramdef>size_t <parameter>sz</parameter></paramdef>
63 </funcprototype>
64
65 <funcprototype>
66 <funcdef>int <function>sd_journal_get_data_threshold</function></funcdef>
67 <paramdef>sd_journal *<parameter>j</parameter></paramdef>
68 <paramdef>size_t *<parameter>sz</parameter></paramdef>
69 </funcprototype>
70 </funcsynopsis>
71 </refsynopsisdiv>
72
73 <refsect1>
74 <title>Description</title>
75
76 <para><function>sd_journal_get_data()</function> gets the data
77 object associated with a specific field from the current journal
78 entry. It takes four arguments: the journal context object, a
79 string with the field name to request, plus a pair of pointers to
80 pointer/size variables where the data object and its size shall be
81 stored in. The field name should be an entry field name.
82 Well-known field names are listed in
83 <citerefentry><refentrytitle>systemd.journal-fields</refentrytitle><manvolnum>7</manvolnum></citerefentry>.
84 The returned data is in a read-only memory map and is only valid
85 until the next invocation of
86 <function>sd_journal_get_data()</function> or
87 <function>sd_journal_enumerate_data()</function>, or the read
88 pointer is altered. Note that the data returned will be prefixed
b938cb90 89 with the field name and '='. Also note that, by default, data fields
798d3a52
ZJS
90 larger than 64K might get truncated to 64K. This threshold may be
91 changed and turned off with
92 <function>sd_journal_set_data_threshold()</function> (see
93 below).</para>
94
95 <para><function>sd_journal_enumerate_data()</function> may be used
96 to iterate through all fields of the current entry. On each
97 invocation the data for the next field is returned. The order of
98 these fields is not defined. The data returned is in the same
99 format as with <function>sd_journal_get_data()</function> and also
100 follows the same life-time semantics.</para>
101
102 <para><function>sd_journal_restart_data()</function> resets the
103 data enumeration index to the beginning of the entry. The next
104 invocation of <function>sd_journal_enumerate_data()</function>
105 will return the first field of the entry again.</para>
106
107 <para>Note that the <function>SD_JOURNAL_FOREACH_DATA()</function>
108 macro may be used as a handy wrapper around
109 <function>sd_journal_restart_data()</function> and
110 <function>sd_journal_enumerate_data()</function>.</para>
111
112 <para>Note that these functions will not work before
113 <citerefentry><refentrytitle>sd_journal_next</refentrytitle><manvolnum>3</manvolnum></citerefentry>
114 (or related call) has been called at least once, in order to
115 position the read pointer at a valid entry.</para>
116
117 <para><function>sd_journal_set_data_threshold()</function> may be
118 used to change the data field size threshold for data returned by
119 <function>sd_journal_get_data()</function>,
120 <function>sd_journal_enumerate_data()</function> and
121 <function>sd_journal_enumerate_unique()</function>. This threshold
122 is a hint only: it indicates that the client program is interested
123 only in the initial parts of the data fields, up to the threshold
ccddd104 124 in size — but the library might still return larger data objects.
798d3a52
ZJS
125 That means applications should not rely exclusively on this
126 setting to limit the size of the data fields returned, but need to
037a3ded 127 apply an explicit size limit on the returned data as well. This
798d3a52
ZJS
128 threshold defaults to 64K by default. To retrieve the complete
129 data fields this threshold should be turned off by setting it to
130 0, so that the library always returns the complete data objects.
131 It is recommended to set this threshold as low as possible since
132 this relieves the library from having to decompress large
133 compressed data objects in full.</para>
134
135 <para><function>sd_journal_get_data_threshold()</function> returns
136 the currently configured data field size threshold.</para>
137 </refsect1>
138
139 <refsect1>
140 <title>Return Value</title>
141
142 <para><function>sd_journal_get_data()</function> returns 0 on
143 success or a negative errno-style error code. If the current entry
144 does not include the specified field, -ENOENT is returned. If
145 <citerefentry><refentrytitle>sd_journal_next</refentrytitle><manvolnum>3</manvolnum></citerefentry>
146 has not been called at least once, -EADDRNOTAVAIL is returned.
147 <function>sd_journal_enumerate_data()</function> returns a
148 positive integer if the next field has been read, 0 when no more
149 fields are known, or a negative errno-style error code.
150 <function>sd_journal_restart_data()</function> returns nothing.
151 <function>sd_journal_set_data_threshold()</function> and
152 <function>sd_journal_get_threshold()</function> return 0 on
153 success or a negative errno-style error code.</para>
154 </refsect1>
155
64a7ef8b
LP
156 <refsect1>
157 <title>Notes</title>
158
159 <xi:include href="threads-aware.xml" xpointer="strict"/>
160
161 <xi:include href="libsystemd-pkgconfig.xml" xpointer="pkgconfig-text"/>
162 </refsect1>
798d3a52
ZJS
163
164 <refsect1>
165 <title>Examples</title>
166
167 <para>See
168 <citerefentry><refentrytitle>sd_journal_next</refentrytitle><manvolnum>3</manvolnum></citerefentry>
169 for a complete example how to use
170 <function>sd_journal_get_data()</function>.</para>
171
172 <para>Use the
173 <function>SD_JOURNAL_FOREACH_DATA</function> macro to
174 iterate through all fields of the current journal
175 entry:</para>
176
1eecafb8 177 <programlisting>…
4171a667 178int print_fields(sd_journal *j) {
798d3a52
ZJS
179 const void *data;
180 size_t length;
181 SD_JOURNAL_FOREACH_DATA(j, data, length)
182 printf("%.*s\n", (int) length, data);
4171a667 183}
1eecafb8 184…</programlisting>
798d3a52
ZJS
185 </refsect1>
186
187 <refsect1>
188 <title>See Also</title>
189
190 <para>
191 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
192 <citerefentry><refentrytitle>systemd.journal-fields</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
193 <citerefentry><refentrytitle>sd-journal</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
194 <citerefentry><refentrytitle>sd_journal_open</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
195 <citerefentry><refentrytitle>sd_journal_next</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
196 <citerefentry><refentrytitle>sd_journal_get_realtime_usec</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
197 <citerefentry><refentrytitle>sd_journal_query_unique</refentrytitle><manvolnum>3</manvolnum></citerefentry>
198 </para>
199 </refsect1>
4171a667
LP
200
201</refentry>