]>
Commit | Line | Data |
---|---|---|
663996b3 MS |
1 | <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>sd_journal_query_unique</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><style> |
2 | a.headerlink { | |
3 | color: #c60f0f; | |
4 | font-size: 0.8em; | |
5 | padding: 0 4px 0 4px; | |
6 | text-decoration: none; | |
7 | visibility: hidden; | |
8 | } | |
9 | ||
10 | a.headerlink:hover { | |
11 | background-color: #c60f0f; | |
12 | color: white; | |
13 | } | |
14 | ||
15 | h1:hover > a.headerlink, h2:hover > a.headerlink, h3:hover > a.headerlink, dt:hover > a.headerlink { | |
16 | visibility: visible; | |
17 | } | |
18 | </style><a href="index.html">Index </a>· | |
19 | <a href="systemd.directives.html">Directives </a>· | |
20 | <a href="../python-systemd/index.html">Python </a>· | |
21 | <a href="../libudev/index.html">libudev </a>· | |
e3bff60a | 22 | <a href="../libudev/index.html">gudev </a><span style="float:right">systemd 220</span><hr><div class="refentry"><a name="sd_journal_query_unique"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>sd_journal_query_unique, sd_journal_enumerate_unique, sd_journal_restart_unique, SD_JOURNAL_FOREACH_UNIQUE — Read unique data fields from the journal</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><pre class="funcsynopsisinfo">#include <systemd/sd-journal.h></pre><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_journal_query_unique</b>(</code></td><td>sd_journal *<var class="pdparam">j</var>, </td></tr><tr><td> </td><td>const char *<var class="pdparam">field</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_journal_enumerate_unique</b>(</code></td><td>sd_journal *<var class="pdparam">j</var>, </td></tr><tr><td> </td><td>const void **<var class="pdparam">data</var>, </td></tr><tr><td> </td><td>size_t *<var class="pdparam">length</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">void <b class="fsfunc">sd_journal_restart_unique</b>(</code></td><td>sd_journal *<var class="pdparam">j</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef"><b class="fsfunc">SD_JOURNAL_FOREACH_UNIQUE</b>(</code></td><td>sd_journal *<var class="pdparam">j</var>, </td></tr><tr><td> </td><td>const void *<var class="pdparam">data</var>, </td></tr><tr><td> </td><td>size_t <var class="pdparam">length</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a name="idm139805773424656"></a><h2 id="Description">Description<a class="headerlink" title="Permalink to this headline" href="#Description">¶</a></h2><p><code class="function">sd_journal_query_unique()</code> queries the |
e735f4d4 MP |
23 | journal for all unique values the specified field can take. It |
24 | takes two arguments: the journal to query and the field name to | |
25 | look for. Well-known field names are listed on | |
26 | <a href="systemd.journal-fields.html"><span class="citerefentry"><span class="refentrytitle">systemd.journal-fields</span>(7)</span></a>. | |
27 | Field names must be specified without a trailing '='. After this | |
28 | function has been executed successfully the field values may be | |
29 | queried using <code class="function">sd_journal_enumerate_unique()</code>. | |
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 | |
32 | that matches.</p><p><code class="function">sd_journal_enumerate_unique()</code> may be | |
33 | used to iterate through all data fields which match the previously | |
34 | selected field name as set with | |
35 | <code class="function">sd_journal_query_unique()</code>. On each invocation | |
36 | the next field data matching the field name is returned. The order | |
37 | of the returned data fields is not defined. It takes three | |
38 | arguments: the journal context object, plus a pair of pointers to | |
39 | pointer/size variables where the data object and its size shall be | |
40 | stored in. The returned data is in a read-only memory map and is | |
41 | only valid until the next invocation of | |
42 | <code class="function">sd_journal_enumerate_unique()</code>. Note that the | |
43 | data returned will be prefixed with the field name and '='. Note | |
44 | that this call is subject to the data field size threshold as | |
45 | controlled by | |
46 | <code class="function">sd_journal_set_data_threshold()</code>.</p><p><code class="function">sd_journal_restart_unique()</code> resets the | |
47 | data enumeration index to the beginning of the list. The next | |
48 | invocation of <code class="function">sd_journal_enumerate_unique()</code> | |
49 | will return the first field data matching the field name | |
50 | again.</p><p>Note that the | |
51 | <code class="function">SD_JOURNAL_FOREACH_UNIQUE()</code> macro may be used | |
52 | as a handy wrapper around | |
53 | <code class="function">sd_journal_restart_unique()</code> and | |
54 | <code class="function">sd_journal_enumerate_unique()</code>.</p><p>Note that these functions currently are not influenced by | |
55 | matches set with <code class="function">sd_journal_add_match()</code> but | |
e3bff60a | 56 | this might change in a later version of this software.</p></div><div class="refsect1"><a name="idm139805768785936"></a><h2 id="Return Value">Return Value<a class="headerlink" title="Permalink to this headline" href="#Return%20Value">¶</a></h2><p><code class="function">sd_journal_query_unique()</code> returns 0 on |
e735f4d4 MP |
57 | success or a negative errno-style error code. |
58 | <code class="function">sd_journal_enumerate_unique()</code> returns a | |
59 | positive integer if the next field data has been read, 0 when no | |
60 | more fields are known, or a negative errno-style error code. | |
61 | <code class="function">sd_journal_restart_unique()</code> returns | |
e3bff60a | 62 | nothing.</p></div><div class="refsect1"><a name="idm139805768782880"></a><h2 id="Notes">Notes<a class="headerlink" title="Permalink to this headline" href="#Notes">¶</a></h2><p>The <code class="function">sd_journal_query_unique()</code>, |
e735f4d4 MP |
63 | <code class="function">sd_journal_enumerate_unique()</code> and |
64 | <code class="function">sd_journal_restart_unique()</code> interfaces are | |
65 | available as a shared library, which can be compiled and linked to | |
66 | with the | |
67 | <code class="constant">libsystemd</code> <a href="http://linux.die.net/man/1/pkg-config"><span class="citerefentry"><span class="refentrytitle">pkg-config</span>(1)</span></a> | |
e3bff60a | 68 | file.</p></div><div class="refsect1"><a name="idm139805768778336"></a><h2 id="Examples">Examples<a class="headerlink" title="Permalink to this headline" href="#Examples">¶</a></h2><p>Use the <code class="function">SD_JOURNAL_FOREACH_UNIQUE</code> macro |
e735f4d4 MP |
69 | to iterate through all values a field of the journal can take. The |
70 | following example lists all unit names referenced in the | |
71 | journal:</p><pre class="programlisting">#include <stdio.h> | |
663996b3 MS |
72 | #include <string.h> |
73 | #include <systemd/sd-journal.h> | |
74 | ||
75 | int main(int argc, char *argv[]) { | |
e735f4d4 MP |
76 | sd_journal *j; |
77 | const void *d; | |
78 | size_t l; | |
79 | int r; | |
663996b3 | 80 | |
e735f4d4 MP |
81 | r = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY); |
82 | if (r < 0) { | |
83 | fprintf(stderr, "Failed to open journal: %s\n", strerror(-r)); | |
84 | return 1; | |
85 | } | |
86 | r = sd_journal_query_unique(j, "_SYSTEMD_UNIT"); | |
87 | if (r < 0) { | |
88 | fprintf(stderr, "Failed to query journal: %s\n", strerror(-r)); | |
89 | return 1; | |
90 | } | |
91 | SD_JOURNAL_FOREACH_UNIQUE(j, d, l) | |
92 | printf("%.*s\n", (int) l, (const char*) d); | |
93 | sd_journal_close(j); | |
94 | return 0; | |
e3bff60a | 95 | }</pre></div><div class="refsect1"><a name="idm139805768774208"></a><h2 id="See Also">See Also<a class="headerlink" title="Permalink to this headline" href="#See%20Also">¶</a></h2><p> |
e735f4d4 MP |
96 | <a href="systemd.html"><span class="citerefentry"><span class="refentrytitle">systemd</span>(1)</span></a>, |
97 | <a href="systemd.journal-fields.html"><span class="citerefentry"><span class="refentrytitle">systemd.journal-fields</span>(7)</span></a>, | |
98 | <a href="sd-journal.html"><span class="citerefentry"><span class="refentrytitle">sd-journal</span>(3)</span></a>, | |
99 | <a href="sd_journal_open.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_open</span>(3)</span></a>, | |
100 | <a href="sd_journal_get_data.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_get_data</span>(3)</span></a>, | |
101 | <a href="sd_journal_add_match.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_add_match</span>(3)</span></a> | |
102 | </p></div></div></body></html> |