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, library or
110           module instance.
111
112       -EADDRNOTAVAIL
113           The read pointer is not positioned at a valid entry;
114           sd_journal_next(3) or a related call has not been called at least
115           once.
116
117       -ENOENT
118           The current entry does not include the specified field.
119
120       -ENOMEM
121           Memory allocation failed.
122
123       -ENOBUFS
124           A compressed entry is too large.
125
126       -E2BIG
127           The data field is too large for this computer architecture (e.g.
128           above 4 GB on a 32-bit architecture).
129
130       -EPROTONOSUPPORT
131           The journal is compressed with an unsupported method or the journal
132           uses an unsupported feature.
133
134       -EBADMSG
135           The journal is corrupted (possibly just the entry being iterated
136           over).
137
138       -EIO
139           An I/O error was reported by the kernel.
140

NOTES

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

EXAMPLES

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

SEE ALSO

171       systemd(1), systemd.journal-fields(7), sd-journal(3),
172       sd_journal_open(3), sd_journal_next(3),
173       sd_journal_get_realtime_usec(3), sd_journal_query_unique(3)
174
175
176
177systemd 254                                             SD_JOURNAL_GET_DATA(3)
Impressum