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">
6 This file is part of systemd.
8 Copyright 2012 Lennart Poettering
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.
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.
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/>.
24 <refentry id=
"sd_journal_get_data">
27 <title>sd_journal_get_data
</title>
28 <productname>systemd
</productname>
32 <contrib>Developer
</contrib>
33 <firstname>Lennart
</firstname>
34 <surname>Poettering
</surname>
35 <email>lennart@poettering.net
</email>
41 <refentrytitle>sd_journal_get_data
</refentrytitle>
42 <manvolnum>3</manvolnum>
46 <refname>sd_journal_get_data
</refname>
47 <refname>sd_journal_enumerate_data
</refname>
48 <refname>sd_journal_restart_data
</refname>
49 <refname>SD_JOURNAL_FOREACH_DATA
</refname>
50 <refname>sd_journal_set_data_threshold
</refname>
51 <refname>sd_journal_get_data_threshold
</refname>
52 <refpurpose>Read data fields from the current journal entry
</refpurpose>
57 <funcsynopsisinfo>#include
<systemd/sd-journal.h
></funcsynopsisinfo>
60 <funcdef>int
<function>sd_journal_get_data
</function></funcdef>
61 <paramdef>sd_journal*
<parameter>j
</parameter></paramdef>
62 <paramdef>const char*
<parameter>field
</parameter></paramdef>
63 <paramdef>const void**
<parameter>data
</parameter></paramdef>
64 <paramdef>size_t*
<parameter>length
</parameter></paramdef>
68 <funcdef>int
<function>sd_journal_enumerate_data
</function></funcdef>
69 <paramdef>sd_journal*
<parameter>j
</parameter></paramdef>
70 <paramdef>const void**
<parameter>data
</parameter></paramdef>
71 <paramdef>size_t*
<parameter>length
</parameter></paramdef>
75 <funcdef>void
<function>sd_journal_restart_data
</function></funcdef>
76 <paramdef>sd_journal*
<parameter>j
</parameter></paramdef>
80 <funcdef><function>SD_JOURNAL_FOREACH_DATA
</function></funcdef>
81 <paramdef>sd_journal*
<parameter>j
</parameter></paramdef>
82 <paramdef>const void*
<parameter>data
</parameter></paramdef>
83 <paramdef>size_t
<parameter>length
</parameter></paramdef>
87 <funcdef>int
<function>sd_journal_set_data_threshold
</function></funcdef>
88 <paramdef>sd_journal*
<parameter>j
</parameter></paramdef>
89 <paramdef>size_t
<parameter>sz
</parameter></paramdef>
93 <funcdef>int
<function>sd_journal_get_data_threshold
</function></funcdef>
94 <paramdef>sd_journal*
<parameter>j
</parameter></paramdef>
95 <paramdef>size_t*
<parameter>sz
</parameter></paramdef>
101 <title>Description
</title>
103 <para><function>sd_journal_get_data()
</function> gets
104 the data object associated with a specific field from
105 the current journal entry. It takes four arguments:
106 the journal context object, a string with the field
107 name to request, plus a pair of pointers to
108 pointer/size variables where the data object and its
109 size shall be stored in. The field name should be an
110 entry field name. Well-known field names are listed in
111 <citerefentry><refentrytitle>systemd.journal-fields
</refentrytitle><manvolnum>7</manvolnum></citerefentry>. The
112 returned data is in a read-only memory map and is only
113 valid until the next invocation of
114 <function>sd_journal_get_data()
</function> or
115 <function>sd_journal_enumerate_data()
</function>, or
116 the read pointer is altered. Note that the data
117 returned will be prefixed with the field name and
118 '='. Also note that by default data fields larger than
119 64K might get truncated to
64K. This threshold may be
120 changed and turned off with
121 <function>sd_journal_set_data_threshold()
</function> (see
124 <para><function>sd_journal_enumerate_data()
</function>
125 may be used to iterate through all fields of the
126 current entry. On each invocation the data for the
127 next field is returned. The order of these fields is
128 not defined. The data returned is in the same format
129 as with
<function>sd_journal_get_data()
</function> and
130 also follows the same life-time semantics.
</para>
132 <para><function>sd_journal_restart_data()
</function>
133 resets the data enumeration index to the beginning of
134 the entry. The next invocation of
135 <function>sd_journal_enumerate_data()
</function> will return the first
136 field of the entry again.
</para>
139 <function>SD_JOURNAL_FOREACH_DATA()
</function> macro
140 may be used as a handy wrapper around
141 <function>sd_journal_restart_data()
</function> and
142 <function>sd_journal_enumerate_data()
</function>.
</para>
144 <para>Note that these functions will not work before
145 <citerefentry><refentrytitle>sd_journal_next
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
146 (or related call) has been called at least
147 once, in order to position the read pointer at a valid entry.
</para>
149 <para><function>sd_journal_set_data_threshold()
</function>
150 may be used to change the data field size threshold
152 <function>sd_journal_get_data()
</function>,
153 <function>sd_journal_enumerate_data()
</function> and
154 <function>sd_journal_enumerate_unique()
</function>. This
155 threshold is a hint only: it indicates that the client
156 program is interested only in the initial parts of the
157 data fields, up to the threshold in size -- but the
158 library might still return larger data objects. That
159 means applications should not rely exclusively on this
160 setting to limit the size of the data fields returned,
161 but need to apply a explicit size limit on the
162 returned data as well. This threshold defaults to
64K
163 by default. To retrieve the complete data fields this
164 threshold should be turned off by setting it to
0, so
165 that the library always returns the complete data
166 objects. It is recommended to set this threshold as
167 low as possible since this relieves the library from
168 having to decompress large compressed data objects in
171 <para><function>sd_journal_get_data_threshold()
</function>
172 returns the currently configured data field size
177 <title>Return Value
</title>
179 <para><function>sd_journal_get_data()
</function>
180 returns
0 on success or a negative errno-style error
181 code. If the current entry does not include the
182 specified field, -ENOENT is returned. If
183 <citerefentry><refentrytitle>sd_journal_next
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
184 has not been called at least once, -EADDRNOTAVAIL is
185 returned.
<function>sd_journal_enumerate_data()
</function>
186 returns a positive integer if the next field has been
187 read,
0 when no more fields are known, or a negative
189 code.
<function>sd_journal_restart_data()
</function>
191 nothing.
<function>sd_journal_set_data_threshold()
</function>
192 and
<function>sd_journal_get_threshold()
</function>
193 return
0 on success or a negative errno-style error
200 <para>The
<function>sd_journal_get_data()
</function>,
201 <function>sd_journal_enumerate_data()
</function>,
202 <function>sd_journal_restart_data()
</function>,
203 <function>sd_journal_set_data_threshold()
</function>
205 <function>sd_journal_get_data_threshold()
</function>
206 interfaces are available as shared library, which can
207 be compiled and linked to with the
208 <constant>libsystemd-journal
</constant> <citerefentry><refentrytitle>pkg-config
</refentrytitle><manvolnum>1</manvolnum></citerefentry>
213 <title>Examples
</title>
216 <citerefentry><refentrytitle>sd_journal_next
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
217 for a complete example how to use
218 <function>sd_journal_get_data()
</function>.
</para>
221 <function>SD_JOURNAL_FOREACH_DATA
</function> macro to
222 iterate through all fields of the current journal
226 int print_fields(sd_journal *j) {
229 SD_JOURNAL_FOREACH_DATA(j, data, length)
230 printf(
"%.*s\n", (int) length, data);
237 <title>See Also
</title>
240 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
241 <citerefentry><refentrytitle>systemd.journal-fields
</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
242 <citerefentry><refentrytitle>sd-journal
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
243 <citerefentry><refentrytitle>sd_journal_open
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
244 <citerefentry><refentrytitle>sd_journal_next
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
245 <citerefentry><refentrytitle>sd_journal_get_realtime_usec
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
246 <citerefentry><refentrytitle>sd_journal_query_unique
</refentrytitle><manvolnum>3</manvolnum></citerefentry>