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