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