1SD_JOURNAL_QUERY_UNIQUE(3)  sd_journal_query_unique SD_JOURNAL_QUERY_UNIQUE(3)
2
3
4

NAME

6       sd_journal_query_unique, sd_journal_enumerate_unique,
7       sd_journal_restart_unique, SD_JOURNAL_FOREACH_UNIQUE - Read unique data
8       fields from the journal
9

SYNOPSIS

11       #include <systemd/sd-journal.h>
12
13       int sd_journal_query_unique(sd_journal *j, const char *field);
14
15       int sd_journal_enumerate_unique(sd_journal *j, const void **data,
16                                       size_t *length);
17
18       void sd_journal_restart_unique(sd_journal *j);
19
20       SD_JOURNAL_FOREACH_UNIQUE(sd_journal *j, const void *data,
21                                 size_t length);
22

DESCRIPTION

24       sd_journal_query_unique() queries the journal for all unique values the
25       specified field can take. It takes two arguments: the journal to query
26       and the field name to look for. Well-known field names are listed on
27       systemd.journal-fields(7). Field names must be specified without a
28       trailing '='. After this function has been executed successfully the
29       field values may be queried using sd_journal_enumerate_unique().
30       Invoking this call a second time will change the field name being
31       queried and reset the enumeration index to the first field value that
32       matches.
33
34       sd_journal_enumerate_unique() may be used to iterate through all data
35       fields which match the previously selected field name as set with
36       sd_journal_query_unique(). On each invocation the next field data
37       matching the field name is returned. The order of the returned data
38       fields is not defined. It takes three arguments: the journal context
39       object, plus a pair of pointers to pointer/size variables where the
40       data object and its size shall be stored in. The returned data is in a
41       read-only memory map and is only valid until the next invocation of
42       sd_journal_enumerate_unique(). Note that the data returned will be
43       prefixed with the field name and '='. Note that this call is subject to
44       the data field size threshold as controlled by
45       sd_journal_set_data_threshold().
46
47       sd_journal_restart_unique() resets the data enumeration index to the
48       beginning of the list. The next invocation of
49       sd_journal_enumerate_unique() will return the first field data matching
50       the field name again.
51
52       Note that the SD_JOURNAL_FOREACH_UNIQUE() macro may be used as a handy
53       wrapper around sd_journal_restart_unique() and
54       sd_journal_enumerate_unique().
55
56       Note that these functions currently are not influenced by matches set
57       with sd_journal_add_match() but this might change in a later version of
58       this software.
59

RETURN VALUE

61       sd_journal_query_unique() returns 0 on success or a negative
62       errno-style error code.  sd_journal_enumerate_unique() returns a
63       positive integer if the next field data has been read, 0 when no more
64       fields are known, or a negative errno-style error code.
65       sd_journal_restart_unique() returns nothing.
66

NOTES

68       The sd_journal_query_unique(), sd_journal_enumerate_unique() and
69       sd_journal_restart_unique() interfaces are available as a shared
70       library, which can be compiled and linked to with the libsystemd pkg-
71       config(1) file.
72

EXAMPLES

74       Use the SD_JOURNAL_FOREACH_UNIQUE macro to iterate through all values a
75       field of the journal can take. The following example lists all unit
76       names referenced in the journal:
77
78           #include <stdio.h>
79           #include <string.h>
80           #include <systemd/sd-journal.h>
81
82           int main(int argc, char *argv[]) {
83             sd_journal *j;
84             const void *d;
85             size_t l;
86             int r;
87
88             r = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY);
89             if (r < 0) {
90               fprintf(stderr, "Failed to open journal: %s\n", strerror(-r));
91               return 1;
92             }
93             r = sd_journal_query_unique(j, "_SYSTEMD_UNIT");
94             if (r < 0) {
95               fprintf(stderr, "Failed to query journal: %s\n", strerror(-r));
96               return 1;
97             }
98             SD_JOURNAL_FOREACH_UNIQUE(j, d, l)
99               printf("%.*s\n", (int) l, (const char*) d);
100             sd_journal_close(j);
101             return 0;
102           }
103

SEE ALSO

105       systemd(1), systemd.journal-fields(7), sd-journal(3),
106       sd_journal_open(3), sd_journal_get_data(3), sd_journal_add_match(3)
107
108
109
110systemd 219                                         SD_JOURNAL_QUERY_UNIQUE(3)
Impressum