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+
8 Copyright 2016 Lennart Poettering
11 <refentry id=
"sd_journal_enumerate_fields" xmlns:
xi=
"http://www.w3.org/2001/XInclude">
14 <title>sd_journal_enumerate_fields
</title>
15 <productname>systemd
</productname>
19 <contrib>Developer
</contrib>
20 <firstname>Lennart
</firstname>
21 <surname>Poettering
</surname>
22 <email>lennart@poettering.net
</email>
28 <refentrytitle>sd_journal_enumerate_fields
</refentrytitle>
29 <manvolnum>3</manvolnum>
33 <refname>sd_journal_enumerate_fields
</refname>
34 <refname>sd_journal_restart_fields
</refname>
35 <refname>SD_JOURNAL_FOREACH_FIELD
</refname>
36 <refpurpose>Read used field names from the journal
</refpurpose>
41 <funcsynopsisinfo>#include
<systemd/sd-journal.h
></funcsynopsisinfo>
44 <funcdef>int
<function>sd_journal_enumerate_fields
</function></funcdef>
45 <paramdef>sd_journal *
<parameter>j
</parameter></paramdef>
46 <paramdef>const char **
<parameter>field
</parameter></paramdef>
50 <funcdef>void
<function>sd_journal_restart_fields
</function></funcdef>
51 <paramdef>sd_journal *
<parameter>j
</parameter></paramdef>
55 <funcdef><function>SD_JOURNAL_FOREACH_FIELD
</function></funcdef>
56 <paramdef>sd_journal *
<parameter>j
</parameter></paramdef>
57 <paramdef>const char *
<parameter>field
</parameter></paramdef>
64 <title>Description
</title>
66 <para><function>sd_journal_enumerate_fields()
</function> may be used to iterate through all field names used in the
67 opened journal files. On each invocation the next field name is returned. The order of the returned field names is
68 not defined. It takes two arguments: the journal context object, plus a pointer to a constant string pointer where
69 the field name is stored in. The returned data is in a read-only memory map and is only valid until the next
70 invocation of
<function>sd_journal_enumerate_fields()
</function>. Note that this call is subject to the data field
71 size threshold as controlled by
<function>sd_journal_set_data_threshold()
</function>.
</para>
73 <para><function>sd_journal_restart_fields()
</function> resets the field name enumeration index to the beginning of
74 the list. The next invocation of
<function>sd_journal_enumerate_fields()
</function> will return the first field
77 <para>The
<function>SD_JOURNAL_FOREACH_FIELD()
</function> macro may be used as a handy wrapper around
78 <function>sd_journal_restart_fields()
</function> and
<function>sd_journal_enumerate_fields()
</function>.
</para>
80 <para>These functions currently are not influenced by matches set with
<function>sd_journal_add_match()
</function>
81 but this might change in a later version of this software.
</para>
83 <para>To retrieve the possible values a specific field can take use
84 <citerefentry><refentrytitle>sd_journal_query_unique
</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
</para>
88 <title>Return Value
</title>
90 <para><function>sd_journal_enumerate_fields()
</function> returns a
91 positive integer if the next field name has been read,
0 when no
92 more field names are known, or a negative errno-style error code.
93 <function>sd_journal_restart_fields()
</function> returns
100 <para>All functions listed here are thread-agnostic and only a single thread may operate
101 on a given
<structname>sd_journal
</structname> object.
</para>
103 <xi:include href=
"libsystemd-pkgconfig.xml" xpointer=
"pkgconfig-text"/>
107 <title>Examples
</title>
109 <para>Use the
<function>SD_JOURNAL_FOREACH_FIELD
</function> macro to iterate through all field names in use in the
110 current journal.
</para>
112 <programlisting>#include
<stdio.h
>
113 #include
<string.h
>
114 #include
<systemd/sd-journal.h
>
116 int main(int argc, char *argv[]) {
121 r = sd_journal_open(
&j, SD_JOURNAL_LOCAL_ONLY);
123 fprintf(stderr,
"Failed to open journal: %s\n", strerror(-r));
126 SD_JOURNAL_FOREACH_FIELD(j, field)
127 printf(
"%s\n", field);
135 <title>See Also
</title>
138 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
139 <citerefentry><refentrytitle>systemd.journal-fields
</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
140 <citerefentry><refentrytitle>sd-journal
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
141 <citerefentry><refentrytitle>sd_journal_open
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
142 <citerefentry><refentrytitle>sd_journal_query_unique
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
143 <citerefentry><refentrytitle>sd_journal_get_data
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
144 <citerefentry><refentrytitle>sd_journal_add_match
</refentrytitle><manvolnum>3</manvolnum></citerefentry>