]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/sd_journal_enumerate_fields.xml
tree-wide: drop 'This file is part of systemd' blurb
[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 Copyright 2016 Lennart Poettering
9 -->
10
11 <refentry id="sd_journal_enumerate_fields" xmlns:xi="http://www.w3.org/2001/XInclude">
12
13 <refentryinfo>
14 <title>sd_journal_enumerate_fields</title>
15 <productname>systemd</productname>
16
17 <authorgroup>
18 <author>
19 <contrib>Developer</contrib>
20 <firstname>Lennart</firstname>
21 <surname>Poettering</surname>
22 <email>lennart@poettering.net</email>
23 </author>
24 </authorgroup>
25 </refentryinfo>
26
27 <refmeta>
28 <refentrytitle>sd_journal_enumerate_fields</refentrytitle>
29 <manvolnum>3</manvolnum>
30 </refmeta>
31
32 <refnamediv>
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>
37 </refnamediv>
38
39 <refsynopsisdiv>
40 <funcsynopsis>
41 <funcsynopsisinfo>#include &lt;systemd/sd-journal.h&gt;</funcsynopsisinfo>
42
43 <funcprototype>
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>
47 </funcprototype>
48
49 <funcprototype>
50 <funcdef>void <function>sd_journal_restart_fields</function></funcdef>
51 <paramdef>sd_journal *<parameter>j</parameter></paramdef>
52 </funcprototype>
53
54 <funcprototype>
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>
58 </funcprototype>
59
60 </funcsynopsis>
61 </refsynopsisdiv>
62
63 <refsect1>
64 <title>Description</title>
65
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>
72
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
75 name again.</para>
76
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>
79
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>
82
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>
85 </refsect1>
86
87 <refsect1>
88 <title>Return Value</title>
89
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
94 nothing.</para>
95 </refsect1>
96
97 <refsect1>
98 <title>Notes</title>
99
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>
102
103 <xi:include href="libsystemd-pkgconfig.xml" xpointer="pkgconfig-text"/>
104 </refsect1>
105
106 <refsect1>
107 <title>Examples</title>
108
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>
111
112 <programlisting>#include &lt;stdio.h&gt;
113 #include &lt;string.h&gt;
114 #include &lt;systemd/sd-journal.h&gt;
115
116 int main(int argc, char *argv[]) {
117 sd_journal *j;
118 const char *field;
119 int r;
120
121 r = sd_journal_open(&amp;j, SD_JOURNAL_LOCAL_ONLY);
122 if (r &lt; 0) {
123 fprintf(stderr, "Failed to open journal: %s\n", strerror(-r));
124 return 1;
125 }
126 SD_JOURNAL_FOREACH_FIELD(j, field)
127 printf("%s\n", field);
128 sd_journal_close(j);
129 return 0;
130 }</programlisting>
131
132 </refsect1>
133
134 <refsect1>
135 <title>See Also</title>
136
137 <para>
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>
145 </para>
146 </refsect1>
147
148 </refentry>