| 1 |
'\" t |
| 2 |
.TH "SD_JOURNAL_QUERY_UNIQUE" "3" "" "systemd 261~rc3" "sd_journal_query_unique" |
| 3 |
.\" ----------------------------------------------------------------- |
| 4 |
.\" * Define some portability stuff |
| 5 |
.\" ----------------------------------------------------------------- |
| 6 |
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 7 |
.\" http://bugs.debian.org/507673 |
| 8 |
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html |
| 9 |
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 10 |
.ie \n(.g .ds Aq \(aq |
| 11 |
.el .ds Aq ' |
| 12 |
.\" ----------------------------------------------------------------- |
| 13 |
.\" * set default formatting |
| 14 |
.\" ----------------------------------------------------------------- |
| 15 |
.\" disable hyphenation |
| 16 |
.nh |
| 17 |
.\" disable justification (adjust text to left margin only) |
| 18 |
.ad l |
| 19 |
.\" ----------------------------------------------------------------- |
| 20 |
.\" * MAIN CONTENT STARTS HERE * |
| 21 |
.\" ----------------------------------------------------------------- |
| 22 |
.SH "NAME" |
| 23 |
sd_journal_query_unique, sd_journal_enumerate_unique, sd_journal_enumerate_available_unique, sd_journal_restart_unique, SD_JOURNAL_FOREACH_UNIQUE \- Read unique data fields from the journal |
| 24 |
.SH "SYNOPSIS" |
| 25 |
.sp |
| 26 |
.ft B |
| 27 |
.nf |
| 28 |
#include <systemd/sd\-journal\&.h> |
| 29 |
.fi |
| 30 |
.ft |
| 31 |
.HP \w'int\ sd_journal_query_unique('u |
| 32 |
.BI "int sd_journal_query_unique(sd_journal\ *" "j" ", const\ char\ *" "field" ");" |
| 33 |
.HP \w'int\ sd_journal_enumerate_available_unique('u |
| 34 |
.BI "int sd_journal_enumerate_available_unique(sd_journal\ *" "j" ", const\ void\ **" "data" ", size_t\ *" "length" ");" |
| 35 |
.HP \w'int\ sd_journal_enumerate_unique('u |
| 36 |
.BI "int sd_journal_enumerate_unique(sd_journal\ *" "j" ", const\ void\ **" "data" ", size_t\ *" "length" ");" |
| 37 |
.HP \w'void\ sd_journal_restart_unique('u |
| 38 |
.BI "void sd_journal_restart_unique(sd_journal\ *" "j" ");" |
| 39 |
.HP \w'SD_JOURNAL_FOREACH_UNIQUE('u |
| 40 |
.BI "SD_JOURNAL_FOREACH_UNIQUE(sd_journal\ *" "j" ", const\ void\ *" "data" ", size_t\ " "length" ");" |
| 41 |
.SH "DESCRIPTION" |
| 42 |
.PP |
| 43 |
\fBsd_journal_query_unique()\fR |
| 44 |
queries the journal for all unique values the specified field can take\&. It takes two arguments: the journal to query and the field name to look for\&. Well\-known field names are listed on |
| 45 |
\fBsystemd.journal-fields\fR(7), but any field can be specified\&. Field names must be specified without a trailing |
| 46 |
"="\&. After this function has been executed successfully the field values may be queried using |
| 47 |
\fBsd_journal_enumerate_unique()\fR |
| 48 |
and |
| 49 |
\fBsd_journal_enumerate_available_unique()\fR\&. Invoking one of those calls will change the field name being queried and reset the enumeration index to the first field value that matches\&. |
| 50 |
.PP |
| 51 |
\fBsd_journal_enumerate_unique()\fR |
| 52 |
may be used to iterate through all data fields which match the previously selected field name as set with |
| 53 |
\fBsd_journal_query_unique()\fR\&. On each invocation the next field data matching the field name is returned\&. The order of the returned data fields is not defined\&. It takes three arguments: the journal object, plus a pair of pointers to pointer/size variables where the data object and its size shall be stored\&. The returned data is in a read\-only memory map and is only valid until the next invocation of |
| 54 |
\fBsd_journal_enumerate_unique()\fR\&. Note that the data returned will be prefixed with the field name and |
| 55 |
"="\&. Note that this call is subject to the data field size threshold as controlled by |
| 56 |
\fBsd_journal_set_data_threshold()\fR |
| 57 |
and only the initial part of the field up to the threshold is returned\&. An error is returned for fields which cannot be retrieved\&. See the error list below for details\&. |
| 58 |
.PP |
| 59 |
\fBsd_journal_enumerate_available_unique()\fR |
| 60 |
is similar to |
| 61 |
\fBsd_journal_enumerate_unique()\fR, but silently skips any fields which may be valid, but are too large or not supported by current implementation\&. |
| 62 |
.PP |
| 63 |
\fBsd_journal_restart_unique()\fR |
| 64 |
resets the data enumeration index to the beginning of the list\&. The next invocation of |
| 65 |
\fBsd_journal_enumerate_unique()\fR |
| 66 |
will return the first field data matching the field name again\&. |
| 67 |
.PP |
| 68 |
Note that the |
| 69 |
\fBSD_JOURNAL_FOREACH_UNIQUE()\fR |
| 70 |
macro may be used as a handy wrapper around |
| 71 |
\fBsd_journal_restart_unique()\fR |
| 72 |
and |
| 73 |
\fBsd_journal_enumerate_available_unique()\fR\&. |
| 74 |
.PP |
| 75 |
Note that these functions currently are not influenced by matches set with |
| 76 |
\fBsd_journal_add_match()\fR |
| 77 |
but this might change in a later version of this software\&. |
| 78 |
.PP |
| 79 |
To enumerate all field names currently in use (and thus all suitable field parameters for |
| 80 |
\fBsd_journal_query_unique()\fR), use the |
| 81 |
\fBsd_journal_enumerate_fields\fR(3) |
| 82 |
call\&. |
| 83 |
.SH "RETURN VALUE" |
| 84 |
.PP |
| 85 |
\fBsd_journal_query_unique()\fR |
| 86 |
returns 0 on success or a negative errno\-style error code\&. |
| 87 |
\fBsd_journal_enumerate_unique()\fR |
| 88 |
and |
| 89 |
\fBsd_journal_query_available_unique()\fR |
| 90 |
return a positive integer if the next field data has been read, 0 when no more fields remain, or a negative errno\-style error code\&. |
| 91 |
\fBsd_journal_restart_unique()\fR |
| 92 |
does not return anything\&. |
| 93 |
.SS "Errors" |
| 94 |
.PP |
| 95 |
Returned errors may indicate the following problems: |
| 96 |
.PP |
| 97 |
\fB\-EINVAL\fR |
| 98 |
.RS 4 |
| 99 |
One of the required parameters is |
| 100 |
\fBNULL\fR |
| 101 |
or invalid\&. For |
| 102 |
\fBsd_journal_get_data()\fR, only the journal context object and field name are required non\-\fBNULL\fR\&. For |
| 103 |
\fBsd_journal_enumerate_data()\fR |
| 104 |
and |
| 105 |
\fBsd_journal_enumerate_available_data()\fR, |
| 106 |
\fIret_data\fR |
| 107 |
and |
| 108 |
\fIret_size\fR |
| 109 |
are required as well\&. |
| 110 |
.sp |
| 111 |
Added in version 246\&. |
| 112 |
.RE |
| 113 |
.PP |
| 114 |
\fB\-ECHILD\fR |
| 115 |
.RS 4 |
| 116 |
The journal object was created in a different process, library or module instance\&. |
| 117 |
.sp |
| 118 |
Added in version 246\&. |
| 119 |
.RE |
| 120 |
.PP |
| 121 |
\fB\-EADDRNOTAVAIL\fR |
| 122 |
.RS 4 |
| 123 |
The read pointer is not positioned at a valid entry; |
| 124 |
\fBsd_journal_next\fR(3) |
| 125 |
or a related call has not been called at least once\&. |
| 126 |
.sp |
| 127 |
Added in version 246\&. |
| 128 |
.RE |
| 129 |
.PP |
| 130 |
\fB\-ENOENT\fR |
| 131 |
.RS 4 |
| 132 |
The current entry does not include the specified field\&. |
| 133 |
.sp |
| 134 |
Added in version 246\&. |
| 135 |
.RE |
| 136 |
.PP |
| 137 |
\fB\-ENOBUFS\fR |
| 138 |
.RS 4 |
| 139 |
A compressed entry is too large\&. |
| 140 |
.sp |
| 141 |
Added in version 246\&. |
| 142 |
.RE |
| 143 |
.PP |
| 144 |
\fB\-E2BIG\fR |
| 145 |
.RS 4 |
| 146 |
The data field is too large for this computer architecture (e\&.g\&. above 4 GB on a 32\-bit architecture)\&. |
| 147 |
.sp |
| 148 |
Added in version 246\&. |
| 149 |
.RE |
| 150 |
.PP |
| 151 |
\fB\-EPROTONOSUPPORT\fR |
| 152 |
.RS 4 |
| 153 |
The journal is compressed with an unsupported method or the journal uses an unsupported feature\&. |
| 154 |
.sp |
| 155 |
Added in version 246\&. |
| 156 |
.RE |
| 157 |
.PP |
| 158 |
\fB\-EBADMSG\fR |
| 159 |
.RS 4 |
| 160 |
The journal is corrupted (possibly just the entry being iterated over)\&. |
| 161 |
.sp |
| 162 |
Added in version 246\&. |
| 163 |
.RE |
| 164 |
.PP |
| 165 |
\fB\-EIO\fR |
| 166 |
.RS 4 |
| 167 |
An I/O error was reported by the kernel\&. |
| 168 |
.sp |
| 169 |
Added in version 246\&. |
| 170 |
.RE |
| 171 |
.SH "NOTES" |
| 172 |
.PP |
| 173 |
All functions listed here are thread\-agnostic and only a single thread may operate on a given object at any given time\&. Different threads may access the same object at different times\&. Multiple independent objects may be used from different threads in parallel\&. |
| 174 |
.PP |
| 175 |
Functions described here are available as a shared library, which can be compiled against and linked to with the |
| 176 |
\fBlibsystemd\fR\ \&\fBpkg-config\fR(1) |
| 177 |
file\&. |
| 178 |
.SH "EXAMPLES" |
| 179 |
.PP |
| 180 |
Use the |
| 181 |
\fBSD_JOURNAL_FOREACH_UNIQUE()\fR |
| 182 |
macro to iterate through all values a field of the journal can take (and which can be accessed on the given architecture and are not compressed with an unsupported mechanism)\&. The following example lists all unit names referenced in the journal: |
| 183 |
.sp |
| 184 |
.if n \{\ |
| 185 |
.RS 4 |
| 186 |
.\} |
| 187 |
.nf |
| 188 |
/* SPDX\-License\-Identifier: MIT\-0 */ |
| 189 |
|
| 190 |
#include <errno\&.h> |
| 191 |
#include <stdio\&.h> |
| 192 |
#include <systemd/sd\-journal\&.h> |
| 193 |
|
| 194 |
int main(int argc, char *argv[]) { |
| 195 |
sd_journal *j; |
| 196 |
const void *d; |
| 197 |
size_t l; |
| 198 |
int r; |
| 199 |
|
| 200 |
r = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY); |
| 201 |
if (r < 0) { |
| 202 |
fprintf(stderr, "Failed to open journal: %s\en", strerror(\-r)); |
| 203 |
return 1; |
| 204 |
} |
| 205 |
r = sd_journal_query_unique(j, "_SYSTEMD_UNIT"); |
| 206 |
if (r < 0) { |
| 207 |
fprintf(stderr, "Failed to query journal: %s\en", strerror(\-r)); |
| 208 |
return 1; |
| 209 |
} |
| 210 |
SD_JOURNAL_FOREACH_UNIQUE(j, d, l) |
| 211 |
printf("%\&.*s\en", (int) l, (const char*) d); |
| 212 |
sd_journal_close(j); |
| 213 |
return 0; |
| 214 |
} |
| 215 |
.fi |
| 216 |
.if n \{\ |
| 217 |
.RE |
| 218 |
.\} |
| 219 |
.SH "HISTORY" |
| 220 |
.PP |
| 221 |
\fBsd_journal_query_unique()\fR, |
| 222 |
\fBsd_journal_enumerate_unique()\fR, |
| 223 |
\fBsd_journal_restart_unique()\fR, and |
| 224 |
\fBSD_JOURNAL_FOREACH_UNIQUE()\fR |
| 225 |
were added in version 195\&. |
| 226 |
.PP |
| 227 |
\fBsd_journal_enumerate_available_unique()\fR |
| 228 |
was added in version 246\&. |
| 229 |
.SH "SEE ALSO" |
| 230 |
.PP |
| 231 |
\fBsystemd\fR(1), \fBsystemd.journal-fields\fR(7), \fBsd-journal\fR(3), \fBsd_journal_open\fR(3), \fBsd_journal_enumerate_fields\fR(3), \fBsd_journal_get_data\fR(3), \fBsd_journal_add_match\fR(3) |