]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/sd_journal_enumerate_fields.xml
verify: use manager_load_startable_unit_or_warn() to load units for verification
[thirdparty/systemd.git] / man / sd_journal_enumerate_fields.xml
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">
4
5 <!--
6 SPDX-License-Identifier: LGPL-2.1+
7
8 This file is part of systemd.
9
10 Copyright 2016 Lennart Poettering
11
12 systemd is free software; you can redistribute it and/or modify it
13 under the terms of the GNU Lesser General Public License as published by
14 the Free Software Foundation; either version 2.1 of the License, or
15 (at your option) any later version.
16
17 systemd is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 Lesser General Public License for more details.
21
22 You should have received a copy of the GNU Lesser General Public License
23 along with systemd; If not, see <http://www.gnu.org/licenses/>.
24 -->
25
26 <refentry id="sd_journal_enumerate_fields">
27
28 <refentryinfo>
29 <title>sd_journal_enumerate_fields</title>
30 <productname>systemd</productname>
31
32 <authorgroup>
33 <author>
34 <contrib>Developer</contrib>
35 <firstname>Lennart</firstname>
36 <surname>Poettering</surname>
37 <email>lennart@poettering.net</email>
38 </author>
39 </authorgroup>
40 </refentryinfo>
41
42 <refmeta>
43 <refentrytitle>sd_journal_enumerate_fields</refentrytitle>
44 <manvolnum>3</manvolnum>
45 </refmeta>
46
47 <refnamediv>
48 <refname>sd_journal_enumerate_fields</refname>
49 <refname>sd_journal_restart_fields</refname>
50 <refname>SD_JOURNAL_FOREACH_FIELD</refname>
51 <refpurpose>Read used field names from the journal</refpurpose>
52 </refnamediv>
53
54 <refsynopsisdiv>
55 <funcsynopsis>
56 <funcsynopsisinfo>#include &lt;systemd/sd-journal.h&gt;</funcsynopsisinfo>
57
58 <funcprototype>
59 <funcdef>int <function>sd_journal_enumerate_fields</function></funcdef>
60 <paramdef>sd_journal *<parameter>j</parameter></paramdef>
61 <paramdef>const char **<parameter>field</parameter></paramdef>
62 </funcprototype>
63
64 <funcprototype>
65 <funcdef>void <function>sd_journal_restart_fields</function></funcdef>
66 <paramdef>sd_journal *<parameter>j</parameter></paramdef>
67 </funcprototype>
68
69 <funcprototype>
70 <funcdef><function>SD_JOURNAL_FOREACH_FIELD</function></funcdef>
71 <paramdef>sd_journal *<parameter>j</parameter></paramdef>
72 <paramdef>const char *<parameter>field</parameter></paramdef>
73 </funcprototype>
74
75 </funcsynopsis>
76 </refsynopsisdiv>
77
78 <refsect1>
79 <title>Description</title>
80
81 <para><function>sd_journal_enumerate_fields()</function> may be used to iterate through all field names used in the
82 opened journal files. On each invocation the next field name is returned. The order of the returned field names is
83 not defined. It takes two arguments: the journal context object, plus a pointer to a constant string pointer where
84 the field name is stored in. The returned data is in a read-only memory map and is only valid until the next
85 invocation of <function>sd_journal_enumerate_fields()</function>. Note that this call is subject to the data field
86 size threshold as controlled by <function>sd_journal_set_data_threshold()</function>.</para>
87
88 <para><function>sd_journal_restart_fields()</function> resets the field name enumeration index to the beginning of
89 the list. The next invocation of <function>sd_journal_enumerate_fields()</function> will return the first field
90 name again.</para>
91
92 <para>The <function>SD_JOURNAL_FOREACH_FIELD()</function> macro may be used as a handy wrapper around
93 <function>sd_journal_restart_fields()</function> and <function>sd_journal_enumerate_fields()</function>.</para>
94
95 <para>These functions currently are not influenced by matches set with <function>sd_journal_add_match()</function>
96 but this might change in a later version of this software.</para>
97
98 <para>To retrieve the possible values a specific field can take use
99 <citerefentry><refentrytitle>sd_journal_query_unique</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para>
100 </refsect1>
101
102 <refsect1>
103 <title>Return Value</title>
104
105 <para><function>sd_journal_enumerate_fields()</function> returns a
106 positive integer if the next field name has been read, 0 when no
107 more field names are known, or a negative errno-style error code.
108 <function>sd_journal_restart_fields()</function> returns
109 nothing.</para>
110 </refsect1>
111
112 <refsect1>
113 <title>Notes</title>
114
115 <para>All functions listed here are thread-agnostic and only a single thread may operate
116 on a given <structname>sd_journal</structname> object.</para>
117
118 <para>The <function>sd_journal_enumerate_fields()</function> and <function>sd_journal_restart_fields()</function>
119 interfaces are available as a shared library, which can be compiled and linked to with the
120 <constant>libsystemd</constant> <citerefentry
121 project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry> file.</para>
122 </refsect1>
123
124 <refsect1>
125 <title>Examples</title>
126
127 <para>Use the <function>SD_JOURNAL_FOREACH_FIELD</function> macro to iterate through all field names in use in the
128 current journal.</para>
129
130 <programlisting>#include &lt;stdio.h&gt;
131 #include &lt;string.h&gt;
132 #include &lt;systemd/sd-journal.h&gt;
133
134 int main(int argc, char *argv[]) {
135 sd_journal *j;
136 const char *field;
137 int r;
138
139 r = sd_journal_open(&amp;j, SD_JOURNAL_LOCAL_ONLY);
140 if (r &lt; 0) {
141 fprintf(stderr, "Failed to open journal: %s\n", strerror(-r));
142 return 1;
143 }
144 SD_JOURNAL_FOREACH_FIELD(j, field)
145 printf("%s\n", field);
146 sd_journal_close(j);
147 return 0;
148 }</programlisting>
149
150 </refsect1>
151
152 <refsect1>
153 <title>See Also</title>
154
155 <para>
156 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
157 <citerefentry><refentrytitle>systemd.journal-fields</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
158 <citerefentry><refentrytitle>sd-journal</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
159 <citerefentry><refentrytitle>sd_journal_open</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
160 <citerefentry><refentrytitle>sd_journal_query_unique</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
161 <citerefentry><refentrytitle>sd_journal_get_data</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
162 <citerefentry><refentrytitle>sd_journal_add_match</refentrytitle><manvolnum>3</manvolnum></citerefentry>
163 </para>
164 </refsect1>
165
166 </refentry>