]>
Commit | Line | Data |
---|---|---|
1a2be33a | 1 | <?xml version='1.0'?> <!--*-nxml-*--> |
3a54a157 | 2 | <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" |
12b42c76 | 3 | "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> |
0307f791 | 4 | <!-- SPDX-License-Identifier: LGPL-2.1+ --> |
1a2be33a | 5 | |
7d6b2723 | 6 | <refentry id="sd_journal_query_unique" xmlns:xi="http://www.w3.org/2001/XInclude"> |
1a2be33a | 7 | |
798d3a52 ZJS |
8 | <refentryinfo> |
9 | <title>sd_journal_query_unique</title> | |
10 | <productname>systemd</productname> | |
798d3a52 ZJS |
11 | </refentryinfo> |
12 | ||
13 | <refmeta> | |
14 | <refentrytitle>sd_journal_query_unique</refentrytitle> | |
15 | <manvolnum>3</manvolnum> | |
16 | </refmeta> | |
17 | ||
18 | <refnamediv> | |
19 | <refname>sd_journal_query_unique</refname> | |
20 | <refname>sd_journal_enumerate_unique</refname> | |
21 | <refname>sd_journal_restart_unique</refname> | |
22 | <refname>SD_JOURNAL_FOREACH_UNIQUE</refname> | |
23 | <refpurpose>Read unique data fields from the journal</refpurpose> | |
24 | </refnamediv> | |
25 | ||
26 | <refsynopsisdiv> | |
27 | <funcsynopsis> | |
28 | <funcsynopsisinfo>#include <systemd/sd-journal.h></funcsynopsisinfo> | |
29 | ||
30 | <funcprototype> | |
31 | <funcdef>int <function>sd_journal_query_unique</function></funcdef> | |
32 | <paramdef>sd_journal *<parameter>j</parameter></paramdef> | |
33 | <paramdef>const char *<parameter>field</parameter></paramdef> | |
34 | </funcprototype> | |
35 | ||
36 | <funcprototype> | |
37 | <funcdef>int <function>sd_journal_enumerate_unique</function></funcdef> | |
38 | <paramdef>sd_journal *<parameter>j</parameter></paramdef> | |
39 | <paramdef>const void **<parameter>data</parameter></paramdef> | |
40 | <paramdef>size_t *<parameter>length</parameter></paramdef> | |
41 | </funcprototype> | |
42 | ||
43 | <funcprototype> | |
44 | <funcdef>void <function>sd_journal_restart_unique</function></funcdef> | |
45 | <paramdef>sd_journal *<parameter>j</parameter></paramdef> | |
46 | </funcprototype> | |
47 | ||
48 | <funcprototype> | |
49 | <funcdef><function>SD_JOURNAL_FOREACH_UNIQUE</function></funcdef> | |
50 | <paramdef>sd_journal *<parameter>j</parameter></paramdef> | |
51 | <paramdef>const void *<parameter>data</parameter></paramdef> | |
52 | <paramdef>size_t <parameter>length</parameter></paramdef> | |
53 | </funcprototype> | |
54 | ||
55 | </funcsynopsis> | |
56 | </refsynopsisdiv> | |
57 | ||
58 | <refsect1> | |
59 | <title>Description</title> | |
60 | ||
61 | <para><function>sd_journal_query_unique()</function> queries the | |
62 | journal for all unique values the specified field can take. It | |
63 | takes two arguments: the journal to query and the field name to | |
64 | look for. Well-known field names are listed on | |
65 | <citerefentry><refentrytitle>systemd.journal-fields</refentrytitle><manvolnum>7</manvolnum></citerefentry>. | |
66 | Field names must be specified without a trailing '='. After this | |
67 | function has been executed successfully the field values may be | |
68 | queried using <function>sd_journal_enumerate_unique()</function>. | |
69 | Invoking this call a second time will change the field name being | |
70 | queried and reset the enumeration index to the first field value | |
71 | that matches.</para> | |
72 | ||
73 | <para><function>sd_journal_enumerate_unique()</function> may be | |
74 | used to iterate through all data fields which match the previously | |
75 | selected field name as set with | |
76 | <function>sd_journal_query_unique()</function>. On each invocation | |
77 | the next field data matching the field name is returned. The order | |
78 | of the returned data fields is not defined. It takes three | |
79 | arguments: the journal context object, plus a pair of pointers to | |
80 | pointer/size variables where the data object and its size shall be | |
81 | stored in. The returned data is in a read-only memory map and is | |
82 | only valid until the next invocation of | |
83 | <function>sd_journal_enumerate_unique()</function>. Note that the | |
84 | data returned will be prefixed with the field name and '='. Note | |
85 | that this call is subject to the data field size threshold as | |
86 | controlled by | |
87 | <function>sd_journal_set_data_threshold()</function>.</para> | |
88 | ||
89 | <para><function>sd_journal_restart_unique()</function> resets the | |
90 | data enumeration index to the beginning of the list. The next | |
91 | invocation of <function>sd_journal_enumerate_unique()</function> | |
92 | will return the first field data matching the field name | |
93 | again.</para> | |
94 | ||
95 | <para>Note that the | |
96 | <function>SD_JOURNAL_FOREACH_UNIQUE()</function> macro may be used | |
97 | as a handy wrapper around | |
98 | <function>sd_journal_restart_unique()</function> and | |
99 | <function>sd_journal_enumerate_unique()</function>.</para> | |
100 | ||
101 | <para>Note that these functions currently are not influenced by | |
102 | matches set with <function>sd_journal_add_match()</function> but | |
103 | this might change in a later version of this software.</para> | |
eb86030e LP |
104 | |
105 | <para>To enumerate all field names currently in use (and thus all suitable field parameters for | |
106 | <function>sd_journal_query_unique()</function>), use the | |
107 | <citerefentry><refentrytitle>sd_journal_enumerate_fields</refentrytitle><manvolnum>3</manvolnum></citerefentry> | |
108 | call.</para> | |
798d3a52 ZJS |
109 | </refsect1> |
110 | ||
111 | <refsect1> | |
112 | <title>Return Value</title> | |
113 | ||
114 | <para><function>sd_journal_query_unique()</function> returns 0 on | |
115 | success or a negative errno-style error code. | |
116 | <function>sd_journal_enumerate_unique()</function> returns a | |
117 | positive integer if the next field data has been read, 0 when no | |
118 | more fields are known, or a negative errno-style error code. | |
119 | <function>sd_journal_restart_unique()</function> returns | |
120 | nothing.</para> | |
121 | </refsect1> | |
122 | ||
123 | <refsect1> | |
124 | <title>Notes</title> | |
125 | ||
64a7ef8b | 126 | <xi:include href="threads-aware.xml" xpointer="strict"/> |
a8d46a16 | 127 | |
7d6b2723 | 128 | <xi:include href="libsystemd-pkgconfig.xml" xpointer="pkgconfig-text"/> |
798d3a52 ZJS |
129 | </refsect1> |
130 | ||
131 | <refsect1> | |
132 | <title>Examples</title> | |
133 | ||
134 | <para>Use the <function>SD_JOURNAL_FOREACH_UNIQUE</function> macro | |
135 | to iterate through all values a field of the journal can take. The | |
136 | following example lists all unit names referenced in the | |
137 | journal:</para> | |
138 | ||
787f78b6 | 139 | <programlisting><xi:include href="journal-iterate-unique.c" parse="text" /></programlisting> |
798d3a52 | 140 | </refsect1> |
1a2be33a | 141 | |
798d3a52 ZJS |
142 | <refsect1> |
143 | <title>See Also</title> | |
1a2be33a | 144 | |
798d3a52 ZJS |
145 | <para> |
146 | <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, | |
147 | <citerefentry><refentrytitle>systemd.journal-fields</refentrytitle><manvolnum>7</manvolnum></citerefentry>, | |
148 | <citerefentry><refentrytitle>sd-journal</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
149 | <citerefentry><refentrytitle>sd_journal_open</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
eb86030e | 150 | <citerefentry><refentrytitle>sd_journal_enumerate_fields</refentrytitle><manvolnum>3</manvolnum></citerefentry>, |
798d3a52 ZJS |
151 | <citerefentry><refentrytitle>sd_journal_get_data</refentrytitle><manvolnum>3</manvolnum></citerefentry>, |
152 | <citerefentry><refentrytitle>sd_journal_add_match</refentrytitle><manvolnum>3</manvolnum></citerefentry> | |
153 | </para> | |
154 | </refsect1> | |
1a2be33a LP |
155 | |
156 | </refentry> |