1SD_JOURNAL_ENUMERATE_FIELDSs(d3_)journal_enumerate_fiSeDl_dJsOURNAL_ENUMERATE_FIELDS(3)
2
3
4
6 sd_journal_enumerate_fields, sd_journal_restart_fields,
7 SD_JOURNAL_FOREACH_FIELD - Read used field names from the journal
8
10 #include <systemd/sd-journal.h>
11
12 int sd_journal_enumerate_fields(sd_journal *j, const char **field);
13
14 void sd_journal_restart_fields(sd_journal *j);
15
16 SD_JOURNAL_FOREACH_FIELD(sd_journal *j, const char *field);
17
19 sd_journal_enumerate_fields() may be used to iterate through all field
20 names used in the opened journal files. On each invocation the next
21 field name is returned. The order of the returned field names is not
22 defined. It takes two arguments: the journal context object, plus a
23 pointer to a constant string pointer where the field name is stored in.
24 The returned data is in a read-only memory map and is only valid until
25 the next invocation of sd_journal_enumerate_fields(). Note that this
26 call is subject to the data field size threshold as controlled by
27 sd_journal_set_data_threshold().
28
29 sd_journal_restart_fields() resets the field name enumeration index to
30 the beginning of the list. The next invocation of
31 sd_journal_enumerate_fields() will return the first field name again.
32
33 The SD_JOURNAL_FOREACH_FIELD() macro may be used as a handy wrapper
34 around sd_journal_restart_fields() and sd_journal_enumerate_fields().
35
36 These functions currently are not influenced by matches set with
37 sd_journal_add_match() but this might change in a later version of this
38 software.
39
40 To retrieve the possible values a specific field can take use
41 sd_journal_query_unique(3).
42
44 sd_journal_enumerate_fields() returns a positive integer if the next
45 field name has been read, 0 when no more field names are known, or a
46 negative errno-style error code. sd_journal_restart_fields() returns
47 nothing.
48
50 All functions listed here are thread-agnostic and only a single
51 specific thread may operate on a given object during its entire
52 lifetime. It's safe to allocate multiple independent objects and use
53 each from a specific thread in parallel. However, it's not safe to
54 allocate such an object in one thread, and operate or free it from any
55 other, even if locking is used to ensure these threads don't operate on
56 it at the very same time.
57
58 These APIs are implemented as a shared library, which can be compiled
59 and linked to with the libsystemd pkg-config(1) file.
60
62 Use the SD_JOURNAL_FOREACH_FIELD macro to iterate through all field
63 names in use in the current journal.
64
65 #include <stdio.h>
66 #include <string.h>
67 #include <systemd/sd-journal.h>
68
69 int main(int argc, char *argv[]) {
70 sd_journal *j;
71 const char *field;
72 int r;
73
74 r = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY);
75 if (r < 0) {
76 fprintf(stderr, "Failed to open journal: %s\n", strerror(-r));
77 return 1;
78 }
79 SD_JOURNAL_FOREACH_FIELD(j, field)
80 printf("%s\n", field);
81 sd_journal_close(j);
82 return 0;
83 }
84
86 systemd(1), systemd.journal-fields(7), sd-journal(3),
87 sd_journal_open(3), sd_journal_query_unique(3), sd_journal_get_data(3),
88 sd_journal_add_match(3)
89
90
91
92systemd 241 SD_JOURNAL_ENUMERATE_FIELDS(3)