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