]>
Commit | Line | Data |
---|---|---|
eb86030e LP |
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 | <!-- | |
572eb058 | 6 | SPDX-License-Identifier: LGPL-2.1+ |
eb86030e LP |
7 | --> |
8 | ||
7d6b2723 | 9 | <refentry id="sd_journal_enumerate_fields" xmlns:xi="http://www.w3.org/2001/XInclude"> |
eb86030e LP |
10 | |
11 | <refentryinfo> | |
12 | <title>sd_journal_enumerate_fields</title> | |
13 | <productname>systemd</productname> | |
14 | ||
15 | <authorgroup> | |
16 | <author> | |
17 | <contrib>Developer</contrib> | |
18 | <firstname>Lennart</firstname> | |
19 | <surname>Poettering</surname> | |
20 | <email>lennart@poettering.net</email> | |
21 | </author> | |
22 | </authorgroup> | |
23 | </refentryinfo> | |
24 | ||
25 | <refmeta> | |
26 | <refentrytitle>sd_journal_enumerate_fields</refentrytitle> | |
27 | <manvolnum>3</manvolnum> | |
28 | </refmeta> | |
29 | ||
30 | <refnamediv> | |
31 | <refname>sd_journal_enumerate_fields</refname> | |
32 | <refname>sd_journal_restart_fields</refname> | |
33 | <refname>SD_JOURNAL_FOREACH_FIELD</refname> | |
34 | <refpurpose>Read used field names from the journal</refpurpose> | |
35 | </refnamediv> | |
36 | ||
37 | <refsynopsisdiv> | |
38 | <funcsynopsis> | |
39 | <funcsynopsisinfo>#include <systemd/sd-journal.h></funcsynopsisinfo> | |
40 | ||
41 | <funcprototype> | |
42 | <funcdef>int <function>sd_journal_enumerate_fields</function></funcdef> | |
43 | <paramdef>sd_journal *<parameter>j</parameter></paramdef> | |
44 | <paramdef>const char **<parameter>field</parameter></paramdef> | |
45 | </funcprototype> | |
46 | ||
47 | <funcprototype> | |
48 | <funcdef>void <function>sd_journal_restart_fields</function></funcdef> | |
49 | <paramdef>sd_journal *<parameter>j</parameter></paramdef> | |
50 | </funcprototype> | |
51 | ||
52 | <funcprototype> | |
53 | <funcdef><function>SD_JOURNAL_FOREACH_FIELD</function></funcdef> | |
54 | <paramdef>sd_journal *<parameter>j</parameter></paramdef> | |
55 | <paramdef>const char *<parameter>field</parameter></paramdef> | |
56 | </funcprototype> | |
57 | ||
58 | </funcsynopsis> | |
59 | </refsynopsisdiv> | |
60 | ||
61 | <refsect1> | |
62 | <title>Description</title> | |
63 | ||
64 | <para><function>sd_journal_enumerate_fields()</function> may be used to iterate through all field names used in the | |
65 | opened journal files. On each invocation the next field name is returned. The order of the returned field names is | |
66 | not defined. It takes two arguments: the journal context object, plus a pointer to a constant string pointer where | |
67 | the field name is stored in. The returned data is in a read-only memory map and is only valid until the next | |
68 | invocation of <function>sd_journal_enumerate_fields()</function>. Note that this call is subject to the data field | |
69 | size threshold as controlled by <function>sd_journal_set_data_threshold()</function>.</para> | |
70 | ||
71 | <para><function>sd_journal_restart_fields()</function> resets the field name enumeration index to the beginning of | |
72 | the list. The next invocation of <function>sd_journal_enumerate_fields()</function> will return the first field | |
73 | name again.</para> | |
74 | ||
75 | <para>The <function>SD_JOURNAL_FOREACH_FIELD()</function> macro may be used as a handy wrapper around | |
76 | <function>sd_journal_restart_fields()</function> and <function>sd_journal_enumerate_fields()</function>.</para> | |
77 | ||
78 | <para>These functions currently are not influenced by matches set with <function>sd_journal_add_match()</function> | |
79 | but this might change in a later version of this software.</para> | |
80 | ||
81 | <para>To retrieve the possible values a specific field can take use | |
82 | <citerefentry><refentrytitle>sd_journal_query_unique</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para> | |
83 | </refsect1> | |
84 | ||
85 | <refsect1> | |
86 | <title>Return Value</title> | |
87 | ||
88 | <para><function>sd_journal_enumerate_fields()</function> returns a | |
89 | positive integer if the next field name has been read, 0 when no | |
90 | more field names are known, or a negative errno-style error code. | |
91 | <function>sd_journal_restart_fields()</function> returns | |
92 | nothing.</para> | |
93 | </refsect1> | |
94 | ||
95 | <refsect1> | |
96 | <title>Notes</title> | |
97 | ||
a8d46a16 ZJS |
98 | <para>All functions listed here are thread-agnostic and only a single thread may operate |
99 | on a given <structname>sd_journal</structname> object.</para> | |
100 | ||
7d6b2723 | 101 | <xi:include href="libsystemd-pkgconfig.xml" xpointer="pkgconfig-text"/> |
eb86030e LP |
102 | </refsect1> |
103 | ||
104 | <refsect1> | |
105 | <title>Examples</title> | |
106 | ||
107 | <para>Use the <function>SD_JOURNAL_FOREACH_FIELD</function> macro to iterate through all field names in use in the | |
108 | current journal.</para> | |
109 | ||
110 | <programlisting>#include <stdio.h> | |
111 | #include <string.h> | |
112 | #include <systemd/sd-journal.h> | |
113 | ||
114 | int main(int argc, char *argv[]) { | |
115 | sd_journal *j; | |
116 | const char *field; | |
117 | int r; | |
118 | ||
119 | r = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY); | |
120 | if (r < 0) { | |
121 | fprintf(stderr, "Failed to open journal: %s\n", strerror(-r)); | |
122 | return 1; | |
123 | } | |
124 | SD_JOURNAL_FOREACH_FIELD(j, field) | |
125 | printf("%s\n", field); | |
126 | sd_journal_close(j); | |
127 | return 0; | |
128 | }</programlisting> | |
129 | ||
130 | </refsect1> | |
131 | ||
132 | <refsect1> | |
133 | <title>See Also</title> | |
134 | ||
135 | <para> | |
136 | <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, | |
137 | <citerefentry><refentrytitle>systemd.journal-fields</refentrytitle><manvolnum>7</manvolnum></citerefentry>, | |
138 | <citerefentry><refentrytitle>sd-journal</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
139 | <citerefentry><refentrytitle>sd_journal_open</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
140 | <citerefentry><refentrytitle>sd_journal_query_unique</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
141 | <citerefentry><refentrytitle>sd_journal_get_data</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
142 | <citerefentry><refentrytitle>sd_journal_add_match</refentrytitle><manvolnum>3</manvolnum></citerefentry> | |
143 | </para> | |
144 | </refsect1> | |
145 | ||
146 | </refentry> |