]> git.proxmox.com Git - systemd.git/blame - man/sd_journal_query_unique.3
Imported Upstream version 218
[systemd.git] / man / sd_journal_query_unique.3
CommitLineData
14228c0d 1'\" t
f47781d8 2.TH "SD_JOURNAL_QUERY_UNIQUE" "3" "" "systemd 218" "sd_journal_query_unique"
14228c0d
MB
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"
23sd_journal_query_unique, sd_journal_enumerate_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
60f067b4 32.BI "int sd_journal_query_unique(sd_journal\ *" "j" ", const\ char\ *" "field" ");"
14228c0d 33.HP \w'int\ sd_journal_enumerate_unique('u
60f067b4 34.BI "int sd_journal_enumerate_unique(sd_journal\ *" "j" ", const\ void\ **" "data" ", size_t\ *" "length" ");"
14228c0d 35.HP \w'void\ sd_journal_restart_unique('u
60f067b4 36.BI "void sd_journal_restart_unique(sd_journal\ *" "j" ");"
14228c0d 37.HP \w'SD_JOURNAL_FOREACH_UNIQUE('u
60f067b4 38.BI "SD_JOURNAL_FOREACH_UNIQUE(sd_journal\ *" "j" ", const\ void\ *" "data" ", size_t\ " "length" ");"
14228c0d
MB
39.SH "DESCRIPTION"
40.PP
41\fBsd_journal_query_unique()\fR
42queries 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
43\fBsystemd.journal-fields\fR(7)\&. Field names must be specified without a trailing \*(Aq=\*(Aq\&. After this function has been executed successfully the field values may be queried using
44\fBsd_journal_enumerate_unique()\fR\&. Invoking this call a second time will change the field name being queried and reset the enumeration index to the first field value that matches\&.
45.PP
46\fBsd_journal_enumerate_unique()\fR
47may be used to iterate through all data fields which match the previously selected field name as set with
48\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 context object, plus a pair of pointers to pointer/size variables where the data object and its size shall be stored in\&. The returned data is in a read\-only memory map and is only valid until the next invocation of
49\fBsd_journal_enumerate_unique()\fR\&. Note that the data returned will be prefixed with the field name and \*(Aq=\*(Aq\&. Note that this call is subject to the data field size threshold as controlled by
50\fBsd_journal_set_data_threshold()\fR\&.
51.PP
52\fBsd_journal_restart_unique()\fR
53resets the data enumeration index to the beginning of the list\&. The next invocation of
54\fBsd_journal_enumerate_unique()\fR
55will return the first field data matching the field name again\&.
56.PP
57Note that the
58\fBSD_JOURNAL_FOREACH_UNIQUE()\fR
59macro may be used as a handy wrapper around
60\fBsd_journal_restart_unique()\fR
61and
62\fBsd_journal_enumerate_unique()\fR\&.
63.PP
64Note that these functions currently are not influenced by matches set with
65\fBsd_journal_add_match()\fR
66but this might change in a later version of this software\&.
67.SH "RETURN VALUE"
68.PP
69\fBsd_journal_query_unique()\fR
70returns 0 on success or a negative errno\-style error code\&.
71\fBsd_journal_enumerate_unique()\fR
72returns a positive integer if the next field data has been read, 0 when no more fields are known, or a negative errno\-style error code\&.
73\fBsd_journal_restart_unique()\fR
74returns nothing\&.
75.SH "NOTES"
76.PP
77The
78\fBsd_journal_query_unique()\fR,
79\fBsd_journal_enumerate_unique()\fR
80and
81\fBsd_journal_restart_unique()\fR
60f067b4
JS
82interfaces are available as a shared library, which can be compiled and linked to with the
83\fBlibsystemd\fR\ \&\fBpkg-config\fR(1)
14228c0d
MB
84file\&.
85.SH "EXAMPLES"
86.PP
87Use the
88\fBSD_JOURNAL_FOREACH_UNIQUE\fR
89macro to iterate through all values a field of the journal can take\&. The following example lists all unit names referenced in the journal:
90.sp
91.if n \{\
92.RS 4
93.\}
94.nf
95#include <stdio\&.h>
96#include <string\&.h>
97#include <systemd/sd\-journal\&.h>
98
99int main(int argc, char *argv[]) {
100 sd_journal *j;
101 const void *d;
102 size_t l;
103 int r;
104
105 r = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY);
106 if (r < 0) {
107 fprintf(stderr, "Failed to open journal: %s\en", strerror(\-r));
108 return 1;
109 }
110 r = sd_journal_query_unique(j, "_SYSTEMD_UNIT");
111 if (r < 0) {
112 fprintf(stderr, "Failed to query journal: %s\en", strerror(\-r));
113 return 1;
114 }
115 SD_JOURNAL_FOREACH_UNIQUE(j, d, l)
116 printf("%\&.*s\en", (int) l, (const char*) d);
117 sd_journal_close(j);
118 return 0;
119}
120.fi
121.if n \{\
122.RE
123.\}
124.SH "SEE ALSO"
125.PP
126\fBsystemd\fR(1),
127\fBsystemd.journal-fields\fR(7),
128\fBsd-journal\fR(3),
129\fBsd_journal_open\fR(3),
130\fBsd_journal_get_data\fR(3),
131\fBsd_journal_add_match\fR(3)