1SD_JOURNAL_GET_DATA(3)        sd_journal_get_data       SD_JOURNAL_GET_DATA(3)
2
3
4

NAME

6       sd_journal_get_data, sd_journal_enumerate_data,
7       sd_journal_enumerate_available_data, sd_journal_restart_data,
8       SD_JOURNAL_FOREACH_DATA, sd_journal_set_data_threshold,
9       sd_journal_get_data_threshold - Read data fields from the current
10       journal entry
11

SYNOPSIS

13       #include <systemd/sd-journal.h>
14
15       int sd_journal_get_data(sd_journal *j, const char *field,
16                               const void **data, size_t *length);
17
18       int sd_journal_enumerate_data(sd_journal *j, const void **data,
19                                     size_t *length);
20
21       int sd_journal_enumerate_available_data(sd_journal *j,
22                                               const void **data,
23                                               size_t *length);
24
25       void sd_journal_restart_data(sd_journal *j);
26
27       SD_JOURNAL_FOREACH_DATA(sd_journal *j, const void *data,
28                               size_t length);
29
30       int sd_journal_set_data_threshold(sd_journal *j, size_t sz);
31
32       int sd_journal_get_data_threshold(sd_journal *j, size_t *sz);
33

DESCRIPTION

35       sd_journal_get_data() gets the data object associated with a specific
36       field from the current journal entry. It takes four arguments: the
37       journal context object, a string with the field name to request, plus a
38       pair of pointers to pointer/size variables where the data object and
39       its size shall be stored in. The field name should be an entry field
40       name. Well-known field names are listed in systemd.journal-fields(7),
41       but any field can be specified. The returned data is in a read-only
42       memory map and is only valid until the next invocation of
43       sd_journal_get_data(), sd_journal_enumerate_data(),
44       sd_journal_enumerate_available_data(), or when the read pointer is
45       altered. Note that the data returned will be prefixed with the field
46       name and "=". Also note that, by default, data fields larger than 64K
47       might get truncated to 64K. This threshold may be changed and turned
48       off with sd_journal_set_data_threshold() (see below).
49
50       sd_journal_enumerate_data() may be used to iterate through all fields
51       of the current entry. On each invocation the data for the next field is
52       returned. The order of these fields is not defined. The data returned
53       is in the same format as with sd_journal_get_data() and also follows
54       the same life-time semantics.
55
56       sd_journal_enumerate_available_data() is similar to
57       sd_journal_enumerate_data(), but silently skips any fields which may be
58       valid, but are too large or not supported by current implementation.
59
60       sd_journal_restart_data() resets the data enumeration index to the
61       beginning of the entry. The next invocation of
62       sd_journal_enumerate_data() will return the first field of the entry
63       again.
64
65       Note that the SD_JOURNAL_FOREACH_DATA() macro may be used as a handy
66       wrapper around sd_journal_restart_data() and
67       sd_journal_enumerate_available_data().
68
69       Note that these functions will not work before sd_journal_next(3) (or
70       related call) has been called at least once, in order to position the
71       read pointer at a valid entry.
72
73       sd_journal_set_data_threshold() may be used to change the data field
74       size threshold for data returned by sd_journal_get_data(),
75       sd_journal_enumerate_data() and sd_journal_enumerate_unique(). This
76       threshold is a hint only: it indicates that the client program is
77       interested only in the initial parts of the data fields, up to the
78       threshold in size — but the library might still return larger data
79       objects. That means applications should not rely exclusively on this
80       setting to limit the size of the data fields returned, but need to
81       apply an explicit size limit on the returned data as well. This
82       threshold defaults to 64K by default. To retrieve the complete data
83       fields this threshold should be turned off by setting it to 0, so that
84       the library always returns the complete data objects. It is recommended
85       to set this threshold as low as possible since this relieves the
86       library from having to decompress large compressed data objects in
87       full.
88
89       sd_journal_get_data_threshold() returns the currently configured data
90       field size threshold.
91

RETURN VALUE

93       sd_journal_get_data() returns 0 on success or a negative errno-style
94       error code.  sd_journal_enumerate_data() and
95       sd_journal_enumerate_available_data() return a positive integer if the
96       next field has been read, 0 when no more fields remain, or a negative
97       errno-style error code.  sd_journal_restart_data() doesn't return
98       anything.  sd_journal_set_data_threshold() and
99       sd_journal_get_threshold() return 0 on success or a negative
100       errno-style error code.
101
102   Errors
103       Returned errors may indicate the following problems:
104
105       -EINVAL
106           One of the required parameters is NULL or invalid.
107
108       -ECHILD
109           The journal object was created in a different process.
110
111       -EADDRNOTAVAIL
112           The read pointer is not positioned at a valid entry;
113           sd_journal_next(3) or a related call has not been called at least
114           once.
115
116       -ENOENT
117           The current entry does not include the specified field.
118
119       -ENOMEM
120           Memory allocation failed.
121
122       -ENOBUFS
123           A compressed entry is too large.
124
125       -E2BIG
126           The data field is too large for this computer architecture (e.g.
127           above 4 GB on a 32-bit architecture).
128
129       -EPROTONOSUPPORT
130           The journal is compressed with an unsupported method or the journal
131           uses an unsupported feature.
132
133       -EBADMSG
134           The journal is corrupted (possibly just the entry being iterated
135           over).
136
137       -EIO
138           An I/O error was reported by the kernel.
139

NOTES

141       All functions listed here are thread-agnostic and only a single
142       specific thread may operate on a given object during its entire
143       lifetime. It's safe to allocate multiple independent objects and use
144       each from a specific thread in parallel. However, it's not safe to
145       allocate such an object in one thread, and operate or free it from any
146       other, even if locking is used to ensure these threads don't operate on
147       it at the very same time.
148
149       These APIs are implemented as a shared library, which can be compiled
150       and linked to with the libsystemd pkg-config(1) file.
151

EXAMPLES

153       See sd_journal_next(3) for a complete example how to use
154       sd_journal_get_data().
155
156       Use the SD_JOURNAL_FOREACH_DATA macro to iterate through all fields of
157       the current journal entry:
158
159           ...
160           int print_fields(sd_journal *j) {
161             const void *data;
162             size_t length;
163             SD_JOURNAL_FOREACH_DATA(j, data, length)
164               printf("%.*s\n", (int) length, data);
165           }
166           ...
167

SEE ALSO

169       systemd(1), systemd.journal-fields(7), sd-journal(3),
170       sd_journal_open(3), sd_journal_next(3),
171       sd_journal_get_realtime_usec(3), sd_journal_query_unique(3)
172
173
174
175systemd 246                                             SD_JOURNAL_GET_DATA(3)
Impressum