2
.\" Title: sd_journal_get_data
3
.\" Author: Lennart Poettering <lennart@poettering.net>
4
.\" Generator: DocBook XSL Stylesheets v1.77.1 <http://docbook.sf.net/>
6
.\" Manual: sd_journal_get_data
10
.TH "SD_JOURNAL_GET_DATA" "3" "" "systemd" "sd_journal_get_data"
11
.\" -----------------------------------------------------------------
12
.\" * Define some portability stuff
13
.\" -----------------------------------------------------------------
14
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15
.\" http://bugs.debian.org/507673
16
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20
.\" -----------------------------------------------------------------
21
.\" * set default formatting
22
.\" -----------------------------------------------------------------
23
.\" disable hyphenation
25
.\" disable justification (adjust text to left margin only)
27
.\" -----------------------------------------------------------------
28
.\" * MAIN CONTENT STARTS HERE *
29
.\" -----------------------------------------------------------------
31
sd_journal_get_data, sd_journal_enumerate_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
36
#include <systemd/sd\-journal\&.h>
39
.HP \w'int\ sd_journal_get_data('u
40
.BI "int sd_journal_get_data(sd_journal*\ " "j" ", const\ char*\ " "field" ", const\ void**\ " "data" ", size_t*\ " "length" ");"
41
.HP \w'int\ sd_journal_enumerate_data('u
42
.BI "int sd_journal_enumerate_data(sd_journal*\ " "j" ", const\ void**\ " "data" ", size_t*\ " "length" ");"
43
.HP \w'void\ sd_journal_restart_data('u
44
.BI "void sd_journal_restart_data(sd_journal*\ " "j" ");"
45
.HP \w'SD_JOURNAL_FOREACH_DATA('u
46
.BI "SD_JOURNAL_FOREACH_DATA(sd_journal*\ " "j" ", const\ void*\ " "data" ", size_t\ " "length" ");"
47
.HP \w'int\ sd_journal_set_data_threshold('u
48
.BI "int sd_journal_set_data_threshold(sd_journal*\ " "j" ", size_t\ " "sz" ");"
49
.HP \w'int\ sd_journal_get_data_threshold('u
50
.BI "int sd_journal_get_data_threshold(sd_journal*\ " "j" ", size_t*\ " "sz" ");"
53
\fBsd_journal_get_data()\fR
54
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
55
\fBsystemd.journal-fields\fR(7)\&. The returned data is in a read\-only memory map and is only valid until the next invocation of
56
\fBsd_journal_get_data()\fR
58
\fBsd_journal_enumerate_data()\fR, or the read pointer is altered\&. Note that the data returned will be prefixed with the field name and \*(Aq=\*(Aq\&. Also note that by default data fields larger than 64K might get truncated to 64K\&. This threshold may be changed and turned off with
59
\fBsd_journal_set_data_threshold()\fR
62
\fBsd_journal_enumerate_data()\fR
63
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
64
\fBsd_journal_get_data()\fR
65
and also follows the same life\-time semantics\&.
67
\fBsd_journal_restart_data()\fR
68
resets the data enumeration index to the beginning of the entry\&. The next invocation of
69
\fBsd_journal_enumerate_data()\fR
70
will return the first field of the entry again\&.
73
\fBSD_JOURNAL_FOREACH_DATA()\fR
74
macro may be used as a handy wrapper around
75
\fBsd_journal_restart_data()\fR
77
\fBsd_journal_enumerate_data()\fR\&.
79
Note that these functions will not work before
80
\fBsd_journal_next\fR(3)
81
(or related call) has been called at least once, in order to position the read pointer at a valid entry\&.
83
\fBsd_journal_set_data_threshold()\fR
84
may be used to change the data field size threshold for data returned by
85
\fBsd_journal_get_data()\fR,
86
\fBsd_journal_enumerate_data()\fR
88
\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 \-\- 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 a 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\&.
90
\fBsd_journal_get_data_threshold()\fR
91
returns the currently configured data field size threshold\&.
94
\fBsd_journal_get_data()\fR
95
returns 0 on success or a negative errno\-style error code\&. If the current entry does not include the specified field \-ENOENT is returned\&. If
96
\fBsd_journal_next\fR(3)
97
has not been called at least once \-EADDRNOTAVAIL is returned\&.
98
\fBsd_journal_enumerate_data()\fR
99
returns a positive integer if the next field has been read, 0 when no more fields are known, or a negative errno\-style error code\&.
100
\fBsd_journal_restart_data()\fR
102
\fBsd_journal_set_data_threshold()\fR
104
\fBsd_journal_get_threshold()\fR
105
return 0 on success or a negative errno\-style error code\&.
109
\fBsd_journal_get_data()\fR,
110
\fBsd_journal_enumerate_data()\fR,
111
\fBsd_journal_restart_data()\fR,
112
\fBsd_journal_set_data_threshold()\fR
114
\fBsd_journal_get_data_threshold()\fR
115
interfaces are available as shared library, which can be compiled and linked to with the
122
\fBsd_journal_next\fR(3)
123
for a complete example how to use
124
\fBsd_journal_get_data()\fR\&.
127
\fBSD_JOURNAL_FOREACH_DATA\fR
128
macro to iterate through all fields of the current journal entry:
135
int print_fields(sd_journal *j) {
138
SD_JOURNAL_FOREACH_DATA(j, data, length)
139
printf("%\&.*s\en", (int) length, data);
150
\fBsystemd.journal-fields\fR(7),
152
\fBsd_journal_open\fR(3),
153
\fBsd_journal_next\fR(3),
154
\fBsd_journal_get_realtime_usec\fR(3),
155
\fBsd_journal_query_unique\fR(3)