1 <?xml version='
1.0'
?> <!--*-nxml-*-->
2 <!DOCTYPE refentry PUBLIC
"-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
6 SPDX-License-Identifier: LGPL-2.1+
9 <refentry id=
"sd_journal_enumerate_fields" xmlns:
xi=
"http://www.w3.org/2001/XInclude">
12 <title>sd_journal_enumerate_fields
</title>
13 <productname>systemd
</productname>
17 <refentrytitle>sd_journal_enumerate_fields
</refentrytitle>
18 <manvolnum>3</manvolnum>
22 <refname>sd_journal_enumerate_fields
</refname>
23 <refname>sd_journal_restart_fields
</refname>
24 <refname>SD_JOURNAL_FOREACH_FIELD
</refname>
25 <refpurpose>Read used field names from the journal
</refpurpose>
30 <funcsynopsisinfo>#include
<systemd/sd-journal.h
></funcsynopsisinfo>
33 <funcdef>int
<function>sd_journal_enumerate_fields
</function></funcdef>
34 <paramdef>sd_journal *
<parameter>j
</parameter></paramdef>
35 <paramdef>const char **
<parameter>field
</parameter></paramdef>
39 <funcdef>void
<function>sd_journal_restart_fields
</function></funcdef>
40 <paramdef>sd_journal *
<parameter>j
</parameter></paramdef>
44 <funcdef><function>SD_JOURNAL_FOREACH_FIELD
</function></funcdef>
45 <paramdef>sd_journal *
<parameter>j
</parameter></paramdef>
46 <paramdef>const char *
<parameter>field
</parameter></paramdef>
53 <title>Description
</title>
55 <para><function>sd_journal_enumerate_fields()
</function> may be used to iterate through all field names used in the
56 opened journal files. On each invocation the next field name is returned. The order of the returned field names is
57 not defined. It takes two arguments: the journal context object, plus a pointer to a constant string pointer where
58 the field name is stored in. The returned data is in a read-only memory map and is only valid until the next
59 invocation of
<function>sd_journal_enumerate_fields()
</function>. Note that this call is subject to the data field
60 size threshold as controlled by
<function>sd_journal_set_data_threshold()
</function>.
</para>
62 <para><function>sd_journal_restart_fields()
</function> resets the field name enumeration index to the beginning of
63 the list. The next invocation of
<function>sd_journal_enumerate_fields()
</function> will return the first field
66 <para>The
<function>SD_JOURNAL_FOREACH_FIELD()
</function> macro may be used as a handy wrapper around
67 <function>sd_journal_restart_fields()
</function> and
<function>sd_journal_enumerate_fields()
</function>.
</para>
69 <para>These functions currently are not influenced by matches set with
<function>sd_journal_add_match()
</function>
70 but this might change in a later version of this software.
</para>
72 <para>To retrieve the possible values a specific field can take use
73 <citerefentry><refentrytitle>sd_journal_query_unique
</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
</para>
77 <title>Return Value
</title>
79 <para><function>sd_journal_enumerate_fields()
</function> returns a
80 positive integer if the next field name has been read,
0 when no
81 more field names are known, or a negative errno-style error code.
82 <function>sd_journal_restart_fields()
</function> returns
89 <para>All functions listed here are thread-agnostic and only a single thread may operate
90 on a given
<structname>sd_journal
</structname> object.
</para>
92 <xi:include href=
"libsystemd-pkgconfig.xml" xpointer=
"pkgconfig-text"/>
96 <title>Examples
</title>
98 <para>Use the
<function>SD_JOURNAL_FOREACH_FIELD
</function> macro to iterate through all field names in use in the
99 current journal.
</para>
101 <programlisting>#include
<stdio.h
>
102 #include
<string.h
>
103 #include
<systemd/sd-journal.h
>
105 int main(int argc, char *argv[]) {
110 r = sd_journal_open(
&j, SD_JOURNAL_LOCAL_ONLY);
112 fprintf(stderr,
"Failed to open journal: %s\n", strerror(-r));
115 SD_JOURNAL_FOREACH_FIELD(j, field)
116 printf(
"%s\n", field);
124 <title>See Also
</title>
127 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
128 <citerefentry><refentrytitle>systemd.journal-fields
</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
129 <citerefentry><refentrytitle>sd-journal
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
130 <citerefentry><refentrytitle>sd_journal_open
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
131 <citerefentry><refentrytitle>sd_journal_query_unique
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
132 <citerefentry><refentrytitle>sd_journal_get_data
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
133 <citerefentry><refentrytitle>sd_journal_add_match
</refentrytitle><manvolnum>3</manvolnum></citerefentry>