]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/sd_journal_get_data.xml
journald: splitt of syslog protocol support into its own file
[thirdparty/systemd.git] / man / sd_journal_get_data.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_get_data">
25
26 <refentryinfo>
27 <title>sd_journal_get_data</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_get_data</refentrytitle>
42 <manvolnum>3</manvolnum>
43 </refmeta>
44
45 <refnamediv>
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 <refpurpose>Read data fields from the current journal entry</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_get_data</function></funcdef>
59 <paramdef>sd_journal* <parameter>j</parameter></paramdef>
60 <paramdef>const char* <parameter>field</parameter></paramdef>
61 <paramdef>const void** <parameter>data</parameter></paramdef>
62 <paramdef>size_t* <parameter>length</parameter></paramdef>
63 </funcprototype>
64
65 <funcprototype>
66 <funcdef>int <function>sd_journal_enumerate_data</function></funcdef>
67 <paramdef>sd_journal* <parameter>j</parameter></paramdef>
68 <paramdef>const void** <parameter>data</parameter></paramdef>
69 <paramdef>size_t* <parameter>length</parameter></paramdef>
70 </funcprototype>
71
72 <funcprototype>
73 <funcdef>int <function>sd_journal_restart_data</function></funcdef>
74 <paramdef>sd_journal* <parameter>j</parameter></paramdef>
75 </funcprototype>
76
77 <funcprototype>
78 <funcdef><function>SD_JOURNAL_FOREACH_DATA</function></funcdef>
79 <paramdef>sd_journal* <parameter>j</parameter></paramdef>
80 <paramdef>const void* <parameter>data</parameter></paramdef>
81 <paramdef>size_t <parameter>length</parameter></paramdef>
82 </funcprototype>
83
84 </funcsynopsis>
85 </refsynopsisdiv>
86
87 <refsect1>
88 <title>Description</title>
89
90 <para><function>sd_journal_get_data()</function> gets
91 the data object associated with a specific field from
92 the current journal entry. It takes four arguments:
93 the journal context object, a string with the field
94 name to request, plus a pair of pointers to
95 pointer/size variables where the data object and its
96 size shall be stored in. The field name should be an
97 entry field name. Well-known field names are listed in
98 <citerefentry><refentrytitle>systemd.journal-fields</refentrytitle><manvolnum>7</manvolnum></citerefentry>. The
99 returned data is in a read-only memory map and is only
100 valid until the next invocation of
101 <function>sd_journal_get_data()</function> or
102 <function>sd_journal_enumerate_data()</function>, or
103 the read pointer is altered. Note that the data
104 returned will be prefixed with the field name and
105 '='.</para>
106
107 <para><function>sd_journal_enumerate_data()</function>
108 may be used to iterate through all fields of the
109 current entry. On each invocation the data for the
110 next field is returned. The order of these fields is
111 not defined. The data returned is in the same format
112 as with <function>sd_journal_get_data()</function> and
113 also follows the same life-time semantics.</para>
114
115 <para><function>sd_journal_restart_data()</function>
116 resets the data enumeration index to the beginning of
117 the entry. The next invocation of
118 <function>sd_journal_enumerate_data()</function> will return the first
119 field of the entry again.</para>
120
121 <para>Note that the
122 <function>SD_JOURNAL_FOREACH_DATA()</function> macro
123 may be used as a wrapper around
124 <function>sd_journal_restart_data()</function> and
125 <function>sd_journal_enumerate_data()</function>.</para>
126
127 <para>Note that these functions will not work before
128 <citerefentry><refentrytitle>sd_journal_next</refentrytitle><manvolnum>3</manvolnum></citerefentry>
129 (or related call) has been called at least
130 once, in order to position the read pointer at a valid entry.</para>
131 </refsect1>
132
133 <refsect1>
134 <title>Return Value</title>
135
136 <para><function>sd_journal_get_data()</function>
137 returns 0 on success or a negative errno-style error
138 code. If the current entry does not include the
139 specified field -ENOENT is returned. If
140 <citerefentry><refentrytitle>sd_journal_next</refentrytitle><manvolnum>3</manvolnum></citerefentry>
141 has not been called at least once -EADDRNOTAVAIL is
142 returned. <function>sd_journal_enumerate_data()</function>
143 returns a positive integer if the next field has been
144 read, 0 when no more fields are known, or a negative
145 errno-style error
146 code. <function>sd_journal_restart_data()</function>
147 returns nothing.</para>
148 </refsect1>
149
150 <refsect1>
151 <title>Notes</title>
152
153 <para>The <function>sd_journal_get_data()</function>,
154 <function>sd_journal_enumerate_data()</function> and
155 <function>sd_journal_restart_data()</function>
156 interfaces are available as shared library, which can
157 be compiled and linked to with the
158 <literal>libsystemd-journal</literal>
159 <citerefentry><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
160 file.</para>
161 </refsect1>
162
163 <refsect1>
164 <title>Examples</title>
165
166 <para>See
167 <citerefentry><refentrytitle>sd_journal_next</refentrytitle><manvolnum>3</manvolnum></citerefentry>
168 for a complete example how to use
169 <function>sd_journal_get_data()</function>.</para>
170
171 <para>Use the
172 <function>SD_JOURNAL_FOREACH_DATA</function> macro to
173 iterate through all fields of the current journal
174 entry:</para>
175
176 <programlisting>...
177 int print_fields(sd_journal *j) {
178 const void *data;
179 size_t l;
180 SD_JOURNAL_FOREACH_DATA(j, data, length)
181 printf("%.*s\n", (int) length, data);
182 }
183 ...</programlisting>
184
185 </refsect1>
186
187 <refsect1>
188 <title>See Also</title>
189
190 <para>
191 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
192 <citerefentry><refentrytitle>systemd.journal-fields</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
193 <citerefentry><refentrytitle>sd-journal</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
194 <citerefentry><refentrytitle>sd_journal_open</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
195 <citerefentry><refentrytitle>sd_journal_next</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
196 <citerefentry><refentrytitle>sd_journal_get_realtime_usec</refentrytitle><manvolnum>3</manvolnum></citerefentry>
197 </para>
198 </refsect1>
199
200 </refentry>