| 1 |
<?xml version='1.0'?> <!--*-nxml-*--> |
| 2 |
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" |
| 3 |
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"> |
| 4 |
<!-- SPDX-License-Identifier: LGPL-2.1-or-later --> |
| 5 |
|
| 6 |
<refentry id="sd_journal_get_data" xmlns:xi="http://www.w3.org/2001/XInclude"> |
| 7 |
|
| 8 |
<refentryinfo> |
| 9 |
<title>sd_journal_get_data</title> |
| 10 |
<productname>systemd</productname> |
| 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_enumerate_available_data</refname> |
| 22 |
<refname>sd_journal_restart_data</refname> |
| 23 |
<refname>SD_JOURNAL_FOREACH_DATA</refname> |
| 24 |
<refname>sd_journal_set_data_threshold</refname> |
| 25 |
<refname>sd_journal_get_data_threshold</refname> |
| 26 |
<refpurpose>Read data fields from the current journal entry</refpurpose> |
| 27 |
</refnamediv> |
| 28 |
|
| 29 |
<refsynopsisdiv> |
| 30 |
<funcsynopsis> |
| 31 |
<funcsynopsisinfo>#include <systemd/sd-journal.h></funcsynopsisinfo> |
| 32 |
|
| 33 |
<funcprototype> |
| 34 |
<funcdef>int <function>sd_journal_get_data</function></funcdef> |
| 35 |
<paramdef>sd_journal *<parameter>j</parameter></paramdef> |
| 36 |
<paramdef>const char *<parameter>field</parameter></paramdef> |
| 37 |
<paramdef>const void **<parameter>data</parameter></paramdef> |
| 38 |
<paramdef>size_t *<parameter>length</parameter></paramdef> |
| 39 |
</funcprototype> |
| 40 |
|
| 41 |
<funcprototype> |
| 42 |
<funcdef>int <function>sd_journal_enumerate_data</function></funcdef> |
| 43 |
<paramdef>sd_journal *<parameter>j</parameter></paramdef> |
| 44 |
<paramdef>const void **<parameter>data</parameter></paramdef> |
| 45 |
<paramdef>size_t *<parameter>length</parameter></paramdef> |
| 46 |
</funcprototype> |
| 47 |
|
| 48 |
<funcprototype> |
| 49 |
<funcdef>int <function>sd_journal_enumerate_available_data</function></funcdef> |
| 50 |
<paramdef>sd_journal *<parameter>j</parameter></paramdef> |
| 51 |
<paramdef>const void **<parameter>data</parameter></paramdef> |
| 52 |
<paramdef>size_t *<parameter>length</parameter></paramdef> |
| 53 |
</funcprototype> |
| 54 |
|
| 55 |
<funcprototype> |
| 56 |
<funcdef>void <function>sd_journal_restart_data</function></funcdef> |
| 57 |
<paramdef>sd_journal *<parameter>j</parameter></paramdef> |
| 58 |
</funcprototype> |
| 59 |
|
| 60 |
<funcprototype> |
| 61 |
<funcdef><function>SD_JOURNAL_FOREACH_DATA</function></funcdef> |
| 62 |
<paramdef>sd_journal *<parameter>j</parameter></paramdef> |
| 63 |
<paramdef>const void *<parameter>data</parameter></paramdef> |
| 64 |
<paramdef>size_t <parameter>length</parameter></paramdef> |
| 65 |
</funcprototype> |
| 66 |
|
| 67 |
<funcprototype> |
| 68 |
<funcdef>int <function>sd_journal_set_data_threshold</function></funcdef> |
| 69 |
<paramdef>sd_journal *<parameter>j</parameter></paramdef> |
| 70 |
<paramdef>size_t <parameter>sz</parameter></paramdef> |
| 71 |
</funcprototype> |
| 72 |
|
| 73 |
<funcprototype> |
| 74 |
<funcdef>int <function>sd_journal_get_data_threshold</function></funcdef> |
| 75 |
<paramdef>sd_journal *<parameter>j</parameter></paramdef> |
| 76 |
<paramdef>size_t *<parameter>sz</parameter></paramdef> |
| 77 |
</funcprototype> |
| 78 |
</funcsynopsis> |
| 79 |
</refsynopsisdiv> |
| 80 |
|
| 81 |
<refsect1> |
| 82 |
<title>Description</title> |
| 83 |
|
| 84 |
<para><function>sd_journal_get_data()</function> gets the data object associated with a specific field |
| 85 |
from the current journal entry. It takes four arguments: the journal context object, a string with the |
| 86 |
field name to request, plus a pair of optional pointers to pointer/size variables where the data object and |
| 87 |
its size shall be stored in. Either pointer may be <constant>NULL</constant>, in which case the corresponding |
| 88 |
value is not returned (this is supported since version 261). The field name should be an entry field name. |
| 89 |
Well-known field names are listed in |
| 90 |
<citerefentry><refentrytitle>systemd.journal-fields</refentrytitle><manvolnum>7</manvolnum></citerefentry>, |
| 91 |
but any field can be specified. The returned data is in a read-only memory map and is only valid until |
| 92 |
the next invocation of <function>sd_journal_get_data()</function>, |
| 93 |
<function>sd_journal_enumerate_data()</function>, |
| 94 |
<function>sd_journal_enumerate_available_data()</function>, or when the read pointer is altered. Note |
| 95 |
that the data returned will be prefixed with the field name and <literal>=</literal>. Also note that, by |
| 96 |
default, data fields larger than 64K might get truncated to 64K. This threshold may be changed and turned |
| 97 |
off with <function>sd_journal_set_data_threshold()</function> (see below).</para> |
| 98 |
|
| 99 |
<para><function>sd_journal_enumerate_data()</function> may be used |
| 100 |
to iterate through all fields of the current entry. On each |
| 101 |
invocation the data for the next field is returned. The order of |
| 102 |
these fields is not defined. The data returned is in the same |
| 103 |
format as with <function>sd_journal_get_data()</function> and also |
| 104 |
follows the same life-time semantics.</para> |
| 105 |
|
| 106 |
<para><function>sd_journal_enumerate_available_data()</function> is similar to |
| 107 |
<function>sd_journal_enumerate_data()</function>, but silently skips any fields which may be valid, but |
| 108 |
are too large or not supported by current implementation.</para> |
| 109 |
|
| 110 |
<para><function>sd_journal_restart_data()</function> resets the |
| 111 |
data enumeration index to the beginning of the entry. The next |
| 112 |
invocation of <function>sd_journal_enumerate_data()</function> |
| 113 |
will return the first field of the entry again.</para> |
| 114 |
|
| 115 |
<para>Note that the <function>SD_JOURNAL_FOREACH_DATA()</function> macro may be used as a handy wrapper |
| 116 |
around <function>sd_journal_restart_data()</function> and |
| 117 |
<function>sd_journal_enumerate_available_data()</function>.</para> |
| 118 |
|
| 119 |
<para>Note that these functions will not work before |
| 120 |
<citerefentry><refentrytitle>sd_journal_next</refentrytitle><manvolnum>3</manvolnum></citerefentry> |
| 121 |
(or related call) has been called at least once, in order to |
| 122 |
position the read pointer at a valid entry.</para> |
| 123 |
|
| 124 |
<para><function>sd_journal_set_data_threshold()</function> may be |
| 125 |
used to change the data field size threshold for data returned by |
| 126 |
<function>sd_journal_get_data()</function>, |
| 127 |
<function>sd_journal_enumerate_data()</function> and |
| 128 |
<function>sd_journal_enumerate_unique()</function>. This threshold |
| 129 |
is a hint only: it indicates that the client program is interested |
| 130 |
only in the initial parts of the data fields, up to the threshold |
| 131 |
in size — but the library might still return larger data objects. |
| 132 |
That means applications should not rely exclusively on this |
| 133 |
setting to limit the size of the data fields returned, but need to |
| 134 |
apply an explicit size limit on the returned data as well. This |
| 135 |
threshold defaults to 64K by default. To retrieve the complete |
| 136 |
data fields this threshold should be turned off by setting it to |
| 137 |
0, so that the library always returns the complete data objects. |
| 138 |
It is recommended to set this threshold as low as possible since |
| 139 |
this relieves the library from having to decompress large |
| 140 |
compressed data objects in full.</para> |
| 141 |
|
| 142 |
<para><function>sd_journal_get_data_threshold()</function> returns |
| 143 |
the currently configured data field size threshold.</para> |
| 144 |
</refsect1> |
| 145 |
|
| 146 |
<refsect1> |
| 147 |
<title>Return Value</title> |
| 148 |
|
| 149 |
<para><function>sd_journal_get_data()</function> returns 0 on success or a negative errno-style error |
| 150 |
code. <function>sd_journal_enumerate_data()</function> and |
| 151 |
<function>sd_journal_enumerate_available_data()</function> return a positive integer if the next field |
| 152 |
has been read, 0 when no more fields remain, or a negative errno-style error code. |
| 153 |
<function>sd_journal_restart_data()</function> does not return anything. |
| 154 |
<function>sd_journal_set_data_threshold()</function> and <function>sd_journal_get_threshold()</function> |
| 155 |
return 0 on success or a negative errno-style error code.</para> |
| 156 |
|
| 157 |
<refsect2> |
| 158 |
<title>Errors</title> |
| 159 |
|
| 160 |
<para>Returned errors may indicate the following problems:</para> |
| 161 |
|
| 162 |
<variablelist> |
| 163 |
<varlistentry id='EINVAL'> |
| 164 |
<term><constant>-EINVAL</constant></term> |
| 165 |
|
| 166 |
<listitem><para>One of the required parameters is <constant>NULL</constant> or invalid. |
| 167 |
For <function>sd_journal_get_data()</function>, only the journal context object and field name |
| 168 |
are required non-<constant>NULL</constant>. For <function>sd_journal_enumerate_data()</function> |
| 169 |
and <function>sd_journal_enumerate_available_data()</function>, |
| 170 |
<parameter>ret_data</parameter> and <parameter>ret_size</parameter> are required as well. |
| 171 |
</para> |
| 172 |
|
| 173 |
<xi:include href="version-info.xml" xpointer="v246"/></listitem> |
| 174 |
</varlistentry> |
| 175 |
|
| 176 |
<varlistentry id='ECHILD'> |
| 177 |
<term><constant>-ECHILD</constant></term> |
| 178 |
|
| 179 |
<listitem><para>The journal object was created in a different process, library or module instance.</para> |
| 180 |
|
| 181 |
<xi:include href="version-info.xml" xpointer="v246"/></listitem> |
| 182 |
</varlistentry> |
| 183 |
|
| 184 |
<varlistentry id='EADDRNOTAVAIL'> |
| 185 |
<term><constant>-EADDRNOTAVAIL</constant></term> |
| 186 |
|
| 187 |
<listitem><para>The read pointer is not positioned at a valid entry; |
| 188 |
<citerefentry><refentrytitle>sd_journal_next</refentrytitle><manvolnum>3</manvolnum></citerefentry> |
| 189 |
or a related call has not been called at least once.</para> |
| 190 |
|
| 191 |
<xi:include href="version-info.xml" xpointer="v246"/></listitem> |
| 192 |
</varlistentry> |
| 193 |
|
| 194 |
<varlistentry id='ENOENT'> |
| 195 |
<term><constant>-ENOENT</constant></term> |
| 196 |
|
| 197 |
<listitem><para>The current entry does not include the specified field.</para> |
| 198 |
|
| 199 |
<xi:include href="version-info.xml" xpointer="v246"/> |
| 200 |
</listitem> |
| 201 |
</varlistentry> |
| 202 |
|
| 203 |
<varlistentry id='ENOMEM'> |
| 204 |
<term><constant>-ENOMEM</constant></term> |
| 205 |
|
| 206 |
<listitem><para>Memory allocation failed.</para> |
| 207 |
|
| 208 |
<xi:include href="version-info.xml" xpointer="v246"/></listitem> |
| 209 |
</varlistentry> |
| 210 |
|
| 211 |
<varlistentry id='ENOBUFS'> |
| 212 |
<term><constant>-ENOBUFS</constant></term> |
| 213 |
|
| 214 |
<listitem><para>A compressed entry is too large.</para> |
| 215 |
|
| 216 |
<xi:include href="version-info.xml" xpointer="v246"/></listitem> |
| 217 |
</varlistentry> |
| 218 |
|
| 219 |
<varlistentry id='E2BIG'> |
| 220 |
<term><constant>-E2BIG</constant></term> |
| 221 |
|
| 222 |
<listitem><para>The data field is too large for this computer architecture (e.g. above 4 GB on a |
| 223 |
32-bit architecture).</para> |
| 224 |
|
| 225 |
<xi:include href="version-info.xml" xpointer="v246"/></listitem> |
| 226 |
</varlistentry> |
| 227 |
|
| 228 |
<varlistentry id='EPROTONOSUPPORT'> |
| 229 |
<term><constant>-EPROTONOSUPPORT</constant></term> |
| 230 |
|
| 231 |
<listitem><para>The journal is compressed with an unsupported method or the journal uses an |
| 232 |
unsupported feature.</para> |
| 233 |
|
| 234 |
<xi:include href="version-info.xml" xpointer="v246"/></listitem> |
| 235 |
</varlistentry> |
| 236 |
|
| 237 |
<varlistentry id='EBADMSG'> |
| 238 |
<term><constant>-EBADMSG</constant></term> |
| 239 |
|
| 240 |
<listitem><para>The journal is corrupted (possibly just the entry being iterated over). |
| 241 |
</para> |
| 242 |
|
| 243 |
<xi:include href="version-info.xml" xpointer="v246"/></listitem> |
| 244 |
</varlistentry> |
| 245 |
|
| 246 |
<varlistentry id='EIO'> |
| 247 |
<term><constant>-EIO</constant></term> |
| 248 |
|
| 249 |
<listitem><para>An I/O error was reported by the kernel.</para> |
| 250 |
|
| 251 |
<xi:include href="version-info.xml" xpointer="v246"/></listitem> |
| 252 |
</varlistentry> |
| 253 |
</variablelist> |
| 254 |
</refsect2> |
| 255 |
</refsect1> |
| 256 |
|
| 257 |
<refsect1> |
| 258 |
<title>Notes</title> |
| 259 |
|
| 260 |
<xi:include href="threads-aware.xml" xpointer="strict"/> |
| 261 |
|
| 262 |
<xi:include href="libsystemd-pkgconfig.xml" xpointer="pkgconfig-text"/> |
| 263 |
</refsect1> |
| 264 |
|
| 265 |
<refsect1> |
| 266 |
<title>Examples</title> |
| 267 |
|
| 268 |
<para>See |
| 269 |
<citerefentry><refentrytitle>sd_journal_next</refentrytitle><manvolnum>3</manvolnum></citerefentry> |
| 270 |
for a complete example how to use |
| 271 |
<function>sd_journal_get_data()</function>.</para> |
| 272 |
|
| 273 |
<para>Use the |
| 274 |
<function>SD_JOURNAL_FOREACH_DATA()</function> macro to |
| 275 |
iterate through all fields of the current journal |
| 276 |
entry:</para> |
| 277 |
|
| 278 |
<programlisting>… |
| 279 |
int print_fields(sd_journal *j) { |
| 280 |
const void *data; |
| 281 |
size_t length; |
| 282 |
SD_JOURNAL_FOREACH_DATA(j, data, length) |
| 283 |
printf("%.*s\n", (int) length, data); |
| 284 |
} |
| 285 |
…</programlisting> |
| 286 |
</refsect1> |
| 287 |
|
| 288 |
<refsect1> |
| 289 |
<title>History</title> |
| 290 |
<para><function>sd_journal_get_data()</function>, |
| 291 |
<function>sd_journal_enumerate_data()</function>, |
| 292 |
<function>sd_journal_restart_data()</function>, and |
| 293 |
<function>SD_JOURNAL_FOREACH_DATA()</function> were added in version 187.</para> |
| 294 |
<para><function>sd_journal_set_data_threshold()</function> and |
| 295 |
<function>sd_journal_get_data_threshold()</function> were added in version 196.</para> |
| 296 |
<para><function>sd_journal_enumerate_available_data()</function> was added in version 246.</para> |
| 297 |
</refsect1> |
| 298 |
|
| 299 |
<refsect1> |
| 300 |
<title>See Also</title> |
| 301 |
|
| 302 |
<para><simplelist type="inline"> |
| 303 |
<member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> |
| 304 |
<member><citerefentry><refentrytitle>systemd.journal-fields</refentrytitle><manvolnum>7</manvolnum></citerefentry></member> |
| 305 |
<member><citerefentry><refentrytitle>sd-journal</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 306 |
<member><citerefentry><refentrytitle>sd_journal_open</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 307 |
<member><citerefentry><refentrytitle>sd_journal_next</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 308 |
<member><citerefentry><refentrytitle>sd_journal_get_realtime_usec</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 309 |
<member><citerefentry><refentrytitle>sd_journal_query_unique</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 310 |
</simplelist></para> |
| 311 |
</refsect1> |
| 312 |
|
| 313 |
</refentry> |