| 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_enumerate_fields" xmlns:xi="http://www.w3.org/2001/XInclude"> |
| 7 |
|
| 8 |
<refentryinfo> |
| 9 |
<title>sd_journal_enumerate_fields</title> |
| 10 |
<productname>systemd</productname> |
| 11 |
</refentryinfo> |
| 12 |
|
| 13 |
<refmeta> |
| 14 |
<refentrytitle>sd_journal_enumerate_fields</refentrytitle> |
| 15 |
<manvolnum>3</manvolnum> |
| 16 |
</refmeta> |
| 17 |
|
| 18 |
<refnamediv> |
| 19 |
<refname>sd_journal_enumerate_fields</refname> |
| 20 |
<refname>sd_journal_restart_fields</refname> |
| 21 |
<refname>SD_JOURNAL_FOREACH_FIELD</refname> |
| 22 |
<refpurpose>Read used field names from the journal</refpurpose> |
| 23 |
</refnamediv> |
| 24 |
|
| 25 |
<refsynopsisdiv> |
| 26 |
<funcsynopsis> |
| 27 |
<funcsynopsisinfo>#include <systemd/sd-journal.h></funcsynopsisinfo> |
| 28 |
|
| 29 |
<funcprototype> |
| 30 |
<funcdef>int <function>sd_journal_enumerate_fields</function></funcdef> |
| 31 |
<paramdef>sd_journal *<parameter>j</parameter></paramdef> |
| 32 |
<paramdef>const char **<parameter>field</parameter></paramdef> |
| 33 |
</funcprototype> |
| 34 |
|
| 35 |
<funcprototype> |
| 36 |
<funcdef>void <function>sd_journal_restart_fields</function></funcdef> |
| 37 |
<paramdef>sd_journal *<parameter>j</parameter></paramdef> |
| 38 |
</funcprototype> |
| 39 |
|
| 40 |
<funcprototype> |
| 41 |
<funcdef><function>SD_JOURNAL_FOREACH_FIELD</function></funcdef> |
| 42 |
<paramdef>sd_journal *<parameter>j</parameter></paramdef> |
| 43 |
<paramdef>const char *<parameter>field</parameter></paramdef> |
| 44 |
</funcprototype> |
| 45 |
|
| 46 |
</funcsynopsis> |
| 47 |
</refsynopsisdiv> |
| 48 |
|
| 49 |
<refsect1> |
| 50 |
<title>Description</title> |
| 51 |
|
| 52 |
<para><function>sd_journal_enumerate_fields()</function> may be used to iterate through all field names used in the |
| 53 |
opened journal files. On each invocation the next field name is returned. The order of the returned field names is |
| 54 |
not defined. It takes two arguments: the journal context object, plus a pointer to a constant string pointer where |
| 55 |
the field name is stored in. The returned data is in a read-only memory map and is only valid until the next |
| 56 |
invocation of <function>sd_journal_enumerate_fields()</function>. Note that this call is subject to the data field |
| 57 |
size threshold as controlled by <function>sd_journal_set_data_threshold()</function>.</para> |
| 58 |
|
| 59 |
<para><function>sd_journal_restart_fields()</function> resets the field name enumeration index to the beginning of |
| 60 |
the list. The next invocation of <function>sd_journal_enumerate_fields()</function> will return the first field |
| 61 |
name again.</para> |
| 62 |
|
| 63 |
<para>The <function>SD_JOURNAL_FOREACH_FIELD()</function> macro may be used as a handy wrapper around |
| 64 |
<function>sd_journal_restart_fields()</function> and <function>sd_journal_enumerate_fields()</function>.</para> |
| 65 |
|
| 66 |
<para>These functions currently are not influenced by matches set with <function>sd_journal_add_match()</function> |
| 67 |
but this might change in a later version of this software.</para> |
| 68 |
|
| 69 |
<para>To retrieve the possible values a specific field can take use |
| 70 |
<citerefentry><refentrytitle>sd_journal_query_unique</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para> |
| 71 |
</refsect1> |
| 72 |
|
| 73 |
<refsect1> |
| 74 |
<title>Return Value</title> |
| 75 |
|
| 76 |
<para><function>sd_journal_enumerate_fields()</function> returns a |
| 77 |
positive integer if the next field name has been read, 0 when no |
| 78 |
more field names are known, or a negative errno-style error code. |
| 79 |
<function>sd_journal_restart_fields()</function> returns |
| 80 |
nothing.</para> |
| 81 |
</refsect1> |
| 82 |
|
| 83 |
<refsect1> |
| 84 |
<title>Notes</title> |
| 85 |
|
| 86 |
<xi:include href="threads-aware.xml" xpointer="strict" /> |
| 87 |
|
| 88 |
<xi:include href="libsystemd-pkgconfig.xml" xpointer="pkgconfig-text"/> |
| 89 |
</refsect1> |
| 90 |
|
| 91 |
<refsect1> |
| 92 |
<title>Examples</title> |
| 93 |
|
| 94 |
<para>Use the <function>SD_JOURNAL_FOREACH_FIELD()</function> macro to iterate through all field names in use in the |
| 95 |
current journal.</para> |
| 96 |
|
| 97 |
<programlisting><xi:include href="journal-enumerate-fields.c" parse="text" /></programlisting> |
| 98 |
</refsect1> |
| 99 |
|
| 100 |
<refsect1> |
| 101 |
<title>History</title> |
| 102 |
<para><function>sd_journal_enumerate_fields()</function>, |
| 103 |
<function>sd_journal_restart_fields()</function>, and |
| 104 |
<function>SD_JOURNAL_FOREACH_FIELD()</function> were added in version 229.</para> |
| 105 |
</refsect1> |
| 106 |
|
| 107 |
<refsect1> |
| 108 |
<title>See Also</title> |
| 109 |
|
| 110 |
<para><simplelist type="inline"> |
| 111 |
<member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> |
| 112 |
<member><citerefentry><refentrytitle>systemd.journal-fields</refentrytitle><manvolnum>7</manvolnum></citerefentry></member> |
| 113 |
<member><citerefentry><refentrytitle>sd-journal</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 114 |
<member><citerefentry><refentrytitle>sd_journal_open</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 115 |
<member><citerefentry><refentrytitle>sd_journal_query_unique</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 116 |
<member><citerefentry><refentrytitle>sd_journal_get_data</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 117 |
<member><citerefentry><refentrytitle>sd_journal_add_match</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 118 |
</simplelist></para> |
| 119 |
</refsect1> |
| 120 |
|
| 121 |
</refentry> |