| 1 |
'\" t |
| 2 |
.TH "SD_JOURNAL_ENUMERATE_FIELDS" "3" "" "systemd 261~rc3" "sd_journal_enumerate_fields" |
| 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_enumerate_fields, sd_journal_restart_fields, SD_JOURNAL_FOREACH_FIELD \- Read used field names 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_enumerate_fields('u |
| 32 |
.BI "int sd_journal_enumerate_fields(sd_journal\ *" "j" ", const\ char\ **" "field" ");" |
| 33 |
.HP \w'void\ sd_journal_restart_fields('u |
| 34 |
.BI "void sd_journal_restart_fields(sd_journal\ *" "j" ");" |
| 35 |
.HP \w'SD_JOURNAL_FOREACH_FIELD('u |
| 36 |
.BI "SD_JOURNAL_FOREACH_FIELD(sd_journal\ *" "j" ", const\ char\ *" "field" ");" |
| 37 |
.SH "DESCRIPTION" |
| 38 |
.PP |
| 39 |
\fBsd_journal_enumerate_fields()\fR |
| 40 |
may be used to iterate through all field names used in the opened journal files\&. On each invocation the next field name is returned\&. The order of the returned field names is not defined\&. It takes two arguments: the journal context object, plus a pointer to a constant string pointer where the field name is stored in\&. The returned data is in a read\-only memory map and is only valid until the next invocation of |
| 41 |
\fBsd_journal_enumerate_fields()\fR\&. Note that this call is subject to the data field size threshold as controlled by |
| 42 |
\fBsd_journal_set_data_threshold()\fR\&. |
| 43 |
.PP |
| 44 |
\fBsd_journal_restart_fields()\fR |
| 45 |
resets the field name enumeration index to the beginning of the list\&. The next invocation of |
| 46 |
\fBsd_journal_enumerate_fields()\fR |
| 47 |
will return the first field name again\&. |
| 48 |
.PP |
| 49 |
The |
| 50 |
\fBSD_JOURNAL_FOREACH_FIELD()\fR |
| 51 |
macro may be used as a handy wrapper around |
| 52 |
\fBsd_journal_restart_fields()\fR |
| 53 |
and |
| 54 |
\fBsd_journal_enumerate_fields()\fR\&. |
| 55 |
.PP |
| 56 |
These functions currently are not influenced by matches set with |
| 57 |
\fBsd_journal_add_match()\fR |
| 58 |
but this might change in a later version of this software\&. |
| 59 |
.PP |
| 60 |
To retrieve the possible values a specific field can take use |
| 61 |
\fBsd_journal_query_unique\fR(3)\&. |
| 62 |
.SH "RETURN VALUE" |
| 63 |
.PP |
| 64 |
\fBsd_journal_enumerate_fields()\fR |
| 65 |
returns a positive integer if the next field name has been read, 0 when no more field names are known, or a negative errno\-style error code\&. |
| 66 |
\fBsd_journal_restart_fields()\fR |
| 67 |
returns nothing\&. |
| 68 |
.SH "NOTES" |
| 69 |
.PP |
| 70 |
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\&. |
| 71 |
.PP |
| 72 |
Functions described here are available as a shared library, which can be compiled against and linked to with the |
| 73 |
\fBlibsystemd\fR\ \&\fBpkg-config\fR(1) |
| 74 |
file\&. |
| 75 |
.SH "EXAMPLES" |
| 76 |
.PP |
| 77 |
Use the |
| 78 |
\fBSD_JOURNAL_FOREACH_FIELD()\fR |
| 79 |
macro to iterate through all field names in use in the current journal\&. |
| 80 |
.sp |
| 81 |
.if n \{\ |
| 82 |
.RS 4 |
| 83 |
.\} |
| 84 |
.nf |
| 85 |
/* SPDX\-License\-Identifier: MIT\-0 */ |
| 86 |
|
| 87 |
#include <errno\&.h> |
| 88 |
#include <stdio\&.h> |
| 89 |
#include <systemd/sd\-journal\&.h> |
| 90 |
|
| 91 |
int main(int argc, char *argv[]) { |
| 92 |
sd_journal *j; |
| 93 |
const char *field; |
| 94 |
int r; |
| 95 |
|
| 96 |
r = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY); |
| 97 |
if (r < 0) { |
| 98 |
fprintf(stderr, "Failed to open journal: %s\en", strerror(\-r)); |
| 99 |
return 1; |
| 100 |
} |
| 101 |
SD_JOURNAL_FOREACH_FIELD(j, field) |
| 102 |
printf("%s\en", field); |
| 103 |
sd_journal_close(j); |
| 104 |
return 0; |
| 105 |
} |
| 106 |
.fi |
| 107 |
.if n \{\ |
| 108 |
.RE |
| 109 |
.\} |
| 110 |
.SH "HISTORY" |
| 111 |
.PP |
| 112 |
\fBsd_journal_enumerate_fields()\fR, |
| 113 |
\fBsd_journal_restart_fields()\fR, and |
| 114 |
\fBSD_JOURNAL_FOREACH_FIELD()\fR |
| 115 |
were added in version 229\&. |
| 116 |
.SH "SEE ALSO" |
| 117 |
.PP |
| 118 |
\fBsystemd\fR(1), \fBsystemd.journal-fields\fR(7), \fBsd-journal\fR(3), \fBsd_journal_open\fR(3), \fBsd_journal_query_unique\fR(3), \fBsd_journal_get_data\fR(3), \fBsd_journal_add_match\fR(3) |