Debian Codegraph @

upstream/debian-trixie/man3/sd_journal_get_data.3

raw
1 '\" t
2 .TH "SD_JOURNAL_GET_DATA" "3" "" "systemd 257.13" "sd_journal_get_data"
3 .\" -----------------------------------------------------------------
4 .\" * Define some portability stuff
5 .\" -----------------------------------------------------------------
6 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 .\" http://bugs.debian.org/507673
8 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
9 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 .ie \n(.g .ds Aq \(aq
11 .el .ds Aq '
12 .\" -----------------------------------------------------------------
13 .\" * set default formatting
14 .\" -----------------------------------------------------------------
15 .\" disable hyphenation
16 .nh
17 .\" disable justification (adjust text to left margin only)
18 .ad l
19 .\" -----------------------------------------------------------------
20 .\" * MAIN CONTENT STARTS HERE *
21 .\" -----------------------------------------------------------------
22 .SH "NAME"
23 sd_journal_get_data, sd_journal_enumerate_data, sd_journal_enumerate_available_data, sd_journal_restart_data, SD_JOURNAL_FOREACH_DATA, sd_journal_set_data_threshold, sd_journal_get_data_threshold \- Read data fields from the current journal entry
24 .SH "SYNOPSIS"
25 .sp
26 .ft B
27 .nf
28 #include <systemd/sd\-journal\&.h>
29 .fi
30 .ft
31 .HP \w'int\ sd_journal_get_data('u
32 .BI "int sd_journal_get_data(sd_journal\ *" "j" ", const\ char\ *" "field" ", const\ void\ **" "data" ", size_t\ *" "length" ");"
33 .HP \w'int\ sd_journal_enumerate_data('u
34 .BI "int sd_journal_enumerate_data(sd_journal\ *" "j" ", const\ void\ **" "data" ", size_t\ *" "length" ");"
35 .HP \w'int\ sd_journal_enumerate_available_data('u
36 .BI "int sd_journal_enumerate_available_data(sd_journal\ *" "j" ", const\ void\ **" "data" ", size_t\ *" "length" ");"
37 .HP \w'void\ sd_journal_restart_data('u
38 .BI "void sd_journal_restart_data(sd_journal\ *" "j" ");"
39 .HP \w'SD_JOURNAL_FOREACH_DATA('u
40 .BI "SD_JOURNAL_FOREACH_DATA(sd_journal\ *" "j" ", const\ void\ *" "data" ", size_t\ " "length" ");"
41 .HP \w'int\ sd_journal_set_data_threshold('u
42 .BI "int sd_journal_set_data_threshold(sd_journal\ *" "j" ", size_t\ " "sz" ");"
43 .HP \w'int\ sd_journal_get_data_threshold('u
44 .BI "int sd_journal_get_data_threshold(sd_journal\ *" "j" ", size_t\ *" "sz" ");"
45 .SH "DESCRIPTION"
46 .PP
47 \fBsd_journal_get_data()\fR
48 gets the data object associated with a specific field from the current journal entry\&. It takes four arguments: the journal context object, a string with the field name to request, plus a pair of pointers to pointer/size variables where the data object and its size shall be stored in\&. The field name should be an entry field name\&. Well\-known field names are listed in
49 \fBsystemd.journal-fields\fR(7), but any field can be specified\&. The returned data is in a read\-only memory map and is only valid until the next invocation of
50 \fBsd_journal_get_data()\fR,
51 \fBsd_journal_enumerate_data()\fR,
52 \fBsd_journal_enumerate_available_data()\fR, or when the read pointer is altered\&. Note that the data returned will be prefixed with the field name and
53 "="\&. Also note that, by default, data fields larger than 64K might get truncated to 64K\&. This threshold may be changed and turned off with
54 \fBsd_journal_set_data_threshold()\fR
55 (see below)\&.
56 .PP
57 \fBsd_journal_enumerate_data()\fR
58 may be used to iterate through all fields of the current entry\&. On each invocation the data for the next field is returned\&. The order of these fields is not defined\&. The data returned is in the same format as with
59 \fBsd_journal_get_data()\fR
60 and also follows the same life\-time semantics\&.
61 .PP
62 \fBsd_journal_enumerate_available_data()\fR
63 is similar to
64 \fBsd_journal_enumerate_data()\fR, but silently skips any fields which may be valid, but are too large or not supported by current implementation\&.
65 .PP
66 \fBsd_journal_restart_data()\fR
67 resets the data enumeration index to the beginning of the entry\&. The next invocation of
68 \fBsd_journal_enumerate_data()\fR
69 will return the first field of the entry again\&.
70 .PP
71 Note that the
72 \fBSD_JOURNAL_FOREACH_DATA()\fR
73 macro may be used as a handy wrapper around
74 \fBsd_journal_restart_data()\fR
75 and
76 \fBsd_journal_enumerate_available_data()\fR\&.
77 .PP
78 Note that these functions will not work before
79 \fBsd_journal_next\fR(3)
80 (or related call) has been called at least once, in order to position the read pointer at a valid entry\&.
81 .PP
82 \fBsd_journal_set_data_threshold()\fR
83 may be used to change the data field size threshold for data returned by
84 \fBsd_journal_get_data()\fR,
85 \fBsd_journal_enumerate_data()\fR
86 and
87 \fBsd_journal_enumerate_unique()\fR\&. This threshold is a hint only: it indicates that the client program is interested only in the initial parts of the data fields, up to the threshold in size \(em but the library might still return larger data objects\&. That means applications should not rely exclusively on this setting to limit the size of the data fields returned, but need to apply an explicit size limit on the returned data as well\&. This threshold defaults to 64K by default\&. To retrieve the complete data fields this threshold should be turned off by setting it to 0, so that the library always returns the complete data objects\&. It is recommended to set this threshold as low as possible since this relieves the library from having to decompress large compressed data objects in full\&.
88 .PP
89 \fBsd_journal_get_data_threshold()\fR
90 returns the currently configured data field size threshold\&.
91 .SH "RETURN VALUE"
92 .PP
93 \fBsd_journal_get_data()\fR
94 returns 0 on success or a negative errno\-style error code\&.
95 \fBsd_journal_enumerate_data()\fR
96 and
97 \fBsd_journal_enumerate_available_data()\fR
98 return a positive integer if the next field has been read, 0 when no more fields remain, or a negative errno\-style error code\&.
99 \fBsd_journal_restart_data()\fR
100 does not return anything\&.
101 \fBsd_journal_set_data_threshold()\fR
102 and
103 \fBsd_journal_get_threshold()\fR
104 return 0 on success or a negative errno\-style error code\&.
105 .SS "Errors"
106 .PP
107 Returned errors may indicate the following problems:
108 .PP
109 \fB\-EINVAL\fR
110 .RS 4
111 One of the required parameters is
112 \fBNULL\fR
113 or invalid\&.
114 .sp
115 Added in version 246\&.
116 .RE
117 .PP
118 \fB\-ECHILD\fR
119 .RS 4
120 The journal object was created in a different process, library or module instance\&.
121 .sp
122 Added in version 246\&.
123 .RE
124 .PP
125 \fB\-EADDRNOTAVAIL\fR
126 .RS 4
127 The read pointer is not positioned at a valid entry;
128 \fBsd_journal_next\fR(3)
129 or a related call has not been called at least once\&.
130 .sp
131 Added in version 246\&.
132 .RE
133 .PP
134 \fB\-ENOENT\fR
135 .RS 4
136 The current entry does not include the specified field\&.
137 .sp
138 Added in version 246\&.
139 .RE
140 .PP
141 \fB\-ENOMEM\fR
142 .RS 4
143 Memory allocation failed\&.
144 .sp
145 Added in version 246\&.
146 .RE
147 .PP
148 \fB\-ENOBUFS\fR
149 .RS 4
150 A compressed entry is too large\&.
151 .sp
152 Added in version 246\&.
153 .RE
154 .PP
155 \fB\-E2BIG\fR
156 .RS 4
157 The data field is too large for this computer architecture (e\&.g\&. above 4 GB on a 32\-bit architecture)\&.
158 .sp
159 Added in version 246\&.
160 .RE
161 .PP
162 \fB\-EPROTONOSUPPORT\fR
163 .RS 4
164 The journal is compressed with an unsupported method or the journal uses an unsupported feature\&.
165 .sp
166 Added in version 246\&.
167 .RE
168 .PP
169 \fB\-EBADMSG\fR
170 .RS 4
171 The journal is corrupted (possibly just the entry being iterated over)\&.
172 .sp
173 Added in version 246\&.
174 .RE
175 .PP
176 \fB\-EIO\fR
177 .RS 4
178 An I/O error was reported by the kernel\&.
179 .sp
180 Added in version 246\&.
181 .RE
182 .SH "NOTES"
183 .PP
184 All functions listed here are thread\-agnostic and only a single thread may operate on a given object at any given time\&. Different threads may access the same object at different times\&. Multiple independent objects may be used from different threads in parallel\&.
185 .PP
186 Functions described here are available as a shared library, which can be compiled against and linked to with the
187 \fBlibsystemd\fR\ \&\fBpkg-config\fR(1)
188 file\&.
189 .SH "EXAMPLES"
190 .PP
191 See
192 \fBsd_journal_next\fR(3)
193 for a complete example how to use
194 \fBsd_journal_get_data()\fR\&.
195 .PP
196 Use the
197 \fBSD_JOURNAL_FOREACH_DATA()\fR
198 macro to iterate through all fields of the current journal entry:
199 .sp
200 .if n \{\
201 .RS 4
202 .\}
203 .nf
204 \&...
205 int print_fields(sd_journal *j) {
206 const void *data;
207 size_t length;
208 SD_JOURNAL_FOREACH_DATA(j, data, length)
209 printf("%\&.*s\en", (int) length, data);
210 }
211 \&...
212 .fi
213 .if n \{\
214 .RE
215 .\}
216 .SH "HISTORY"
217 .PP
218 \fBsd_journal_get_data()\fR,
219 \fBsd_journal_enumerate_data()\fR,
220 \fBsd_journal_restart_data()\fR, and
221 \fBSD_JOURNAL_FOREACH_DATA()\fR
222 were added in version 187\&.
223 .PP
224 \fBsd_journal_set_data_threshold()\fR
225 and
226 \fBsd_journal_get_data_threshold()\fR
227 were added in version 196\&.
228 .PP
229 \fBsd_journal_enumerate_available_data()\fR
230 was added in version 246\&.
231 .SH "SEE ALSO"
232 .PP
233 \fBsystemd\fR(1), \fBsystemd.journal-fields\fR(7), \fBsd-journal\fR(3), \fBsd_journal_open\fR(3), \fBsd_journal_next\fR(3), \fBsd_journal_get_realtime_usec\fR(3), \fBsd_journal_query_unique\fR(3)