mirror of
https://git.proxmox.com/git/systemd
synced 2025-06-06 02:28:17 +00:00
113 lines
9.7 KiB
HTML
113 lines
9.7 KiB
HTML
<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>
|
||
a.headerlink {
|
||
color: #c60f0f;
|
||
font-size: 0.8em;
|
||
padding: 0 4px 0 4px;
|
||
text-decoration: none;
|
||
visibility: hidden;
|
||
}
|
||
|
||
a.headerlink:hover {
|
||
background-color: #c60f0f;
|
||
color: white;
|
||
}
|
||
|
||
h1:hover > a.headerlink, h2:hover > a.headerlink, h3:hover > a.headerlink, dt:hover > a.headerlink {
|
||
visibility: visible;
|
||
}
|
||
</style><a href="index.html">Index </a>·
|
||
<a href="systemd.directives.html">Directives </a>·
|
||
<a href="../python-systemd/index.html">Python </a>·
|
||
<a href="../libudev/index.html">libudev </a>·
|
||
<a href="../libudev/index.html">gudev </a><span style="float:right">systemd 204</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="idm259782903840"></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 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
|
||
<a href="systemd.journal-fields.html"><span class="citerefentry"><span class="refentrytitle">systemd.journal-fields</span>(7)</span></a>. Field
|
||
names must be specified without a trailing '='. After
|
||
this function has been executed successfully the field
|
||
values may be queried using
|
||
<code class="function">sd_journal_enumerate_unique()</code>. 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.</p><p><code class="function">sd_journal_enumerate_unique()</code>
|
||
may be used to iterate through all data fields which
|
||
match the previously selected field name as set with
|
||
<code class="function">sd_journal_query_unique()</code>. 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
|
||
<code class="function">sd_journal_enumerate_unique()</code>. Note
|
||
that the data returned will be prefixed with the field
|
||
name and '='. Note that this call is subject to the
|
||
data field size threshold as controlled by
|
||
<code class="function">sd_journal_set_data_threshold()</code>.</p><p><code class="function">sd_journal_restart_unique()</code>
|
||
resets the data enumeration index to the beginning of
|
||
the list. The next invocation of
|
||
<code class="function">sd_journal_enumerate_unique()</code>
|
||
will return the first field data matching the field
|
||
name again.</p><p>Note that the
|
||
<code class="function">SD_JOURNAL_FOREACH_UNIQUE()</code> macro
|
||
may be used as a handy wrapper around
|
||
<code class="function">sd_journal_restart_unique()</code> and
|
||
<code class="function">sd_journal_enumerate_unique()</code>.</p><p>Note that these functions currently are not
|
||
influenced by matches set with
|
||
<code class="function">sd_journal_add_match()</code> but this
|
||
might change in a later version of this
|
||
software.</p></div><div class="refsect1"><a name="idm259782890000"></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 success or a negative errno-style error
|
||
code. <code class="function">sd_journal_enumerate_unique()</code>
|
||
returns 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. <code class="function">sd_journal_restart_unique()</code>
|
||
returns nothing.</p></div><div class="refsect1"><a name="idm259782878928"></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>,
|
||
<code class="function">sd_journal_enumerate_unique()</code> and
|
||
<code class="function">sd_journal_restart_unique()</code>
|
||
interfaces are available as shared library, which can
|
||
be compiled and linked to with the
|
||
<code class="literal">libsystemd-journal</code>
|
||
<a href="pkg-config.html"><span class="citerefentry"><span class="refentrytitle">pkg-config</span>(1)</span></a>
|
||
file.</p></div><div class="refsect1"><a name="idm259782873808"></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
|
||
to iterate through all values a field of the journal
|
||
can take. The following example lists all unit names
|
||
referenced in the journal:</p><pre class="programlisting">#include <stdio.h>
|
||
#include <string.h>
|
||
#include <systemd/sd-journal.h>
|
||
|
||
int main(int argc, char *argv[]) {
|
||
sd_journal *j;
|
||
const void *d;
|
||
size_t l;
|
||
int r;
|
||
|
||
r = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY);
|
||
if (r < 0) {
|
||
fprintf(stderr, "Failed to open journal: %s\n", strerror(-r));
|
||
return 1;
|
||
}
|
||
r = sd_journal_query_unique(j, "_SYSTEMD_UNIT");
|
||
if (r < 0) {
|
||
fprintf(stderr, "Failed to query journal: %s\n", strerror(-r));
|
||
return 1;
|
||
}
|
||
SD_JOURNAL_FOREACH_UNIQUE(j, d, l)
|
||
printf("%.*s\n", (int) l, (const char*) d);
|
||
sd_journal_close(j);
|
||
return 0;
|
||
}</pre></div><div class="refsect1"><a name="idm259782869328"></a><h2 id="See Also">See Also<a class="headerlink" title="Permalink to this headline" href="#See%20Also">¶</a></h2><p>
|
||
<a href="systemd.html"><span class="citerefentry"><span class="refentrytitle">systemd</span>(1)</span></a>,
|
||
<a href="systemd.journal-fields.html"><span class="citerefentry"><span class="refentrytitle">systemd.journal-fields</span>(7)</span></a>,
|
||
<a href="sd-journal.html"><span class="citerefentry"><span class="refentrytitle">sd-journal</span>(3)</span></a>,
|
||
<a href="sd_journal_open.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_open</span>(3)</span></a>,
|
||
<a href="sd_journal_get_data.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_get_data</span>(3)</span></a>,
|
||
<a href="sd_journal_add_match.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_add_match</span>(3)</span></a>
|
||
</p></div></div></body></html>
|