]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/sd_journal_query_unique.xml
Merge pull request #2512 from 0xAX/mount-setup
[thirdparty/systemd.git] / man / sd_journal_query_unique.xml
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 2012 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_query_unique">
25
26 <refentryinfo>
27 <title>sd_journal_query_unique</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_query_unique</refentrytitle>
42 <manvolnum>3</manvolnum>
43 </refmeta>
44
45 <refnamediv>
46 <refname>sd_journal_query_unique</refname>
47 <refname>sd_journal_enumerate_unique</refname>
48 <refname>sd_journal_restart_unique</refname>
49 <refname>SD_JOURNAL_FOREACH_UNIQUE</refname>
50 <refpurpose>Read unique data fields from the journal</refpurpose>
51 </refnamediv>
52
53 <refsynopsisdiv>
54 <funcsynopsis>
55 <funcsynopsisinfo>#include &lt;systemd/sd-journal.h&gt;</funcsynopsisinfo>
56
57 <funcprototype>
58 <funcdef>int <function>sd_journal_query_unique</function></funcdef>
59 <paramdef>sd_journal *<parameter>j</parameter></paramdef>
60 <paramdef>const char *<parameter>field</parameter></paramdef>
61 </funcprototype>
62
63 <funcprototype>
64 <funcdef>int <function>sd_journal_enumerate_unique</function></funcdef>
65 <paramdef>sd_journal *<parameter>j</parameter></paramdef>
66 <paramdef>const void **<parameter>data</parameter></paramdef>
67 <paramdef>size_t *<parameter>length</parameter></paramdef>
68 </funcprototype>
69
70 <funcprototype>
71 <funcdef>void <function>sd_journal_restart_unique</function></funcdef>
72 <paramdef>sd_journal *<parameter>j</parameter></paramdef>
73 </funcprototype>
74
75 <funcprototype>
76 <funcdef><function>SD_JOURNAL_FOREACH_UNIQUE</function></funcdef>
77 <paramdef>sd_journal *<parameter>j</parameter></paramdef>
78 <paramdef>const void *<parameter>data</parameter></paramdef>
79 <paramdef>size_t <parameter>length</parameter></paramdef>
80 </funcprototype>
81
82 </funcsynopsis>
83 </refsynopsisdiv>
84
85 <refsect1>
86 <title>Description</title>
87
88 <para><function>sd_journal_query_unique()</function> queries the
89 journal for all unique values the specified field can take. It
90 takes two arguments: the journal to query and the field name to
91 look for. Well-known field names are listed on
92 <citerefentry><refentrytitle>systemd.journal-fields</refentrytitle><manvolnum>7</manvolnum></citerefentry>.
93 Field names must be specified without a trailing '='. After this
94 function has been executed successfully the field values may be
95 queried using <function>sd_journal_enumerate_unique()</function>.
96 Invoking this call a second time will change the field name being
97 queried and reset the enumeration index to the first field value
98 that matches.</para>
99
100 <para><function>sd_journal_enumerate_unique()</function> may be
101 used to iterate through all data fields which match the previously
102 selected field name as set with
103 <function>sd_journal_query_unique()</function>. On each invocation
104 the next field data matching the field name is returned. The order
105 of the returned data fields is not defined. It takes three
106 arguments: the journal context object, plus a pair of pointers to
107 pointer/size variables where the data object and its size shall be
108 stored in. The returned data is in a read-only memory map and is
109 only valid until the next invocation of
110 <function>sd_journal_enumerate_unique()</function>. Note that the
111 data returned will be prefixed with the field name and '='. Note
112 that this call is subject to the data field size threshold as
113 controlled by
114 <function>sd_journal_set_data_threshold()</function>.</para>
115
116 <para><function>sd_journal_restart_unique()</function> resets the
117 data enumeration index to the beginning of the list. The next
118 invocation of <function>sd_journal_enumerate_unique()</function>
119 will return the first field data matching the field name
120 again.</para>
121
122 <para>Note that the
123 <function>SD_JOURNAL_FOREACH_UNIQUE()</function> macro may be used
124 as a handy wrapper around
125 <function>sd_journal_restart_unique()</function> and
126 <function>sd_journal_enumerate_unique()</function>.</para>
127
128 <para>Note that these functions currently are not influenced by
129 matches set with <function>sd_journal_add_match()</function> but
130 this might change in a later version of this software.</para>
131
132 <para>To enumerate all field names currently in use (and thus all suitable field parameters for
133 <function>sd_journal_query_unique()</function>), use the
134 <citerefentry><refentrytitle>sd_journal_enumerate_fields</refentrytitle><manvolnum>3</manvolnum></citerefentry>
135 call.</para>
136 </refsect1>
137
138 <refsect1>
139 <title>Return Value</title>
140
141 <para><function>sd_journal_query_unique()</function> returns 0 on
142 success or a negative errno-style error code.
143 <function>sd_journal_enumerate_unique()</function> returns a
144 positive integer if the next field data has been read, 0 when no
145 more fields are known, or a negative errno-style error code.
146 <function>sd_journal_restart_unique()</function> returns
147 nothing.</para>
148 </refsect1>
149
150 <refsect1>
151 <title>Notes</title>
152
153 <para>The <function>sd_journal_query_unique()</function>,
154 <function>sd_journal_enumerate_unique()</function> and
155 <function>sd_journal_restart_unique()</function> interfaces are
156 available as a shared library, which can be compiled and linked to
157 with the
158 <constant>libsystemd</constant> <citerefentry project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
159 file.</para>
160 </refsect1>
161
162 <refsect1>
163 <title>Examples</title>
164
165 <para>Use the <function>SD_JOURNAL_FOREACH_UNIQUE</function> macro
166 to iterate through all values a field of the journal can take. The
167 following example lists all unit names referenced in the
168 journal:</para>
169
170 <programlisting>#include &lt;stdio.h&gt;
171 #include &lt;string.h&gt;
172 #include &lt;systemd/sd-journal.h&gt;
173
174 int main(int argc, char *argv[]) {
175 sd_journal *j;
176 const void *d;
177 size_t l;
178 int r;
179
180 r = sd_journal_open(&amp;j, SD_JOURNAL_LOCAL_ONLY);
181 if (r &lt; 0) {
182 fprintf(stderr, "Failed to open journal: %s\n", strerror(-r));
183 return 1;
184 }
185 r = sd_journal_query_unique(j, "_SYSTEMD_UNIT");
186 if (r &lt; 0) {
187 fprintf(stderr, "Failed to query journal: %s\n", strerror(-r));
188 return 1;
189 }
190 SD_JOURNAL_FOREACH_UNIQUE(j, d, l)
191 printf("%.*s\n", (int) l, (const char*) d);
192 sd_journal_close(j);
193 return 0;
194 }</programlisting>
195
196 </refsect1>
197
198 <refsect1>
199 <title>See Also</title>
200
201 <para>
202 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
203 <citerefentry><refentrytitle>systemd.journal-fields</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
204 <citerefentry><refentrytitle>sd-journal</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
205 <citerefentry><refentrytitle>sd_journal_open</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
206 <citerefentry><refentrytitle>sd_journal_enumerate_fields</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
207 <citerefentry><refentrytitle>sd_journal_get_data</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
208 <citerefentry><refentrytitle>sd_journal_add_match</refentrytitle><manvolnum>3</manvolnum></citerefentry>
209 </para>
210 </refsect1>
211
212 </refentry>