]> git.proxmox.com Git - systemd.git/blame - man/SD_JOURNAL_FOREACH_DATA.html
Imported Upstream version 220
[systemd.git] / man / SD_JOURNAL_FOREACH_DATA.html
CommitLineData
663996b3
MS
1<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>sd_journal_get_data</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_get_data"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>sd_journal_get_data, sd_journal_enumerate_data, sd_journal_restart_data, SD_JOURNAL_FOREACH_DATA, sd_journal_set_data_threshold, sd_journal_get_data_threshold — Read data fields from the current journal entry</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><pre class="funcsynopsisinfo">#include &lt;systemd/sd-journal.h&gt;</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_get_data</b>(</code></td><td>sd_journal *<var class="pdparam">j</var>, </td></tr><tr><td> </td><td>const char *<var class="pdparam">field</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">int <b class="fsfunc">sd_journal_enumerate_data</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_data</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_DATA</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">int <b class="fsfunc">sd_journal_set_data_threshold</b>(</code></td><td>sd_journal *<var class="pdparam">j</var>, </td></tr><tr><td> </td><td>size_t <var class="pdparam">sz</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_get_data_threshold</b>(</code></td><td>sd_journal *<var class="pdparam">j</var>, </td></tr><tr><td> </td><td>size_t *<var class="pdparam">sz</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a name="idm140169296629136"></a><h2 id="Description">Description<a class="headerlink" title="Permalink to this headline" href="#Description">¶</a></h2><p><code class="function">sd_journal_get_data()</code> gets the data
e735f4d4
MP
23 object associated with a specific field from the current journal
24 entry. It takes four arguments: the journal context object, a
25 string with the field name to request, plus a pair of pointers to
26 pointer/size variables where the data object and its size shall be
27 stored in. The field name should be an entry field name.
28 Well-known field names are listed in
29 <a href="systemd.journal-fields.html"><span class="citerefentry"><span class="refentrytitle">systemd.journal-fields</span>(7)</span></a>.
30 The returned data is in a read-only memory map and is only valid
31 until the next invocation of
32 <code class="function">sd_journal_get_data()</code> or
33 <code class="function">sd_journal_enumerate_data()</code>, or the read
34 pointer is altered. Note that the data returned will be prefixed
35 with the field name and '='. Also note that by default data fields
36 larger than 64K might get truncated to 64K. This threshold may be
37 changed and turned off with
38 <code class="function">sd_journal_set_data_threshold()</code> (see
39 below).</p><p><code class="function">sd_journal_enumerate_data()</code> may be used
40 to iterate through all fields of the current entry. On each
41 invocation the data for the next field is returned. The order of
42 these fields is not defined. The data returned is in the same
43 format as with <code class="function">sd_journal_get_data()</code> and also
44 follows the same life-time semantics.</p><p><code class="function">sd_journal_restart_data()</code> resets the
45 data enumeration index to the beginning of the entry. The next
46 invocation of <code class="function">sd_journal_enumerate_data()</code>
47 will return the first field of the entry again.</p><p>Note that the <code class="function">SD_JOURNAL_FOREACH_DATA()</code>
48 macro may be used as a handy wrapper around
49 <code class="function">sd_journal_restart_data()</code> and
50 <code class="function">sd_journal_enumerate_data()</code>.</p><p>Note that these functions will not work before
51 <a href="sd_journal_next.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_next</span>(3)</span></a>
52 (or related call) has been called at least once, in order to
53 position the read pointer at a valid entry.</p><p><code class="function">sd_journal_set_data_threshold()</code> may be
54 used to change the data field size threshold for data returned by
55 <code class="function">sd_journal_get_data()</code>,
56 <code class="function">sd_journal_enumerate_data()</code> and
57 <code class="function">sd_journal_enumerate_unique()</code>. This threshold
58 is a hint only: it indicates that the client program is interested
59 only in the initial parts of the data fields, up to the threshold
60 in size -- but the library might still return larger data objects.
61 That means applications should not rely exclusively on this
62 setting to limit the size of the data fields returned, but need to
63 apply a explicit size limit on the returned data as well. This
64 threshold defaults to 64K by default. To retrieve the complete
65 data fields this threshold should be turned off by setting it to
66 0, so that the library always returns the complete data objects.
67 It is recommended to set this threshold as low as possible since
68 this relieves the library from having to decompress large
69 compressed data objects in full.</p><p><code class="function">sd_journal_get_data_threshold()</code> returns
e3bff60a 70 the currently configured data field size threshold.</p></div><div class="refsect1"><a name="idm140169296612688"></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_get_data()</code> returns 0 on
e735f4d4
MP
71 success or a negative errno-style error code. If the current entry
72 does not include the specified field, -ENOENT is returned. If
73 <a href="sd_journal_next.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_next</span>(3)</span></a>
74 has not been called at least once, -EADDRNOTAVAIL is returned.
75 <code class="function">sd_journal_enumerate_data()</code> returns a
76 positive integer if the next field has been read, 0 when no more
77 fields are known, or a negative errno-style error code.
78 <code class="function">sd_journal_restart_data()</code> returns nothing.
79 <code class="function">sd_journal_set_data_threshold()</code> and
80 <code class="function">sd_journal_get_threshold()</code> return 0 on
e3bff60a 81 success or a negative errno-style error code.</p></div><div class="refsect1"><a name="idm140169296607344"></a><h2 id="Notes">Notes<a class="headerlink" title="Permalink to this headline" href="#Notes">¶</a></h2><p>The <code class="function">sd_journal_get_data()</code>,
e735f4d4
MP
82 <code class="function">sd_journal_enumerate_data()</code>,
83 <code class="function">sd_journal_restart_data()</code>,
84 <code class="function">sd_journal_set_data_threshold()</code> and
85 <code class="function">sd_journal_get_data_threshold()</code> interfaces
86 are available as a shared library, which can be compiled and
87 linked to with the
88 <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 89 file.</p></div><div class="refsect1"><a name="idm140169296601552"></a><h2 id="Examples">Examples<a class="headerlink" title="Permalink to this headline" href="#Examples">¶</a></h2><p>See
e735f4d4
MP
90 <a href="sd_journal_next.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_next</span>(3)</span></a>
91 for a complete example how to use
92 <code class="function">sd_journal_get_data()</code>.</p><p>Use the
93 <code class="function">SD_JOURNAL_FOREACH_DATA</code> macro to
94 iterate through all fields of the current journal
95 entry:</p><pre class="programlisting">...
663996b3 96int print_fields(sd_journal *j) {
e735f4d4
MP
97 const void *data;
98 size_t length;
99 SD_JOURNAL_FOREACH_DATA(j, data, length)
100 printf("%.*s\n", (int) length, data);
663996b3 101}
e3bff60a 102...</pre></div><div class="refsect1"><a name="idm140169296597104"></a><h2 id="See Also">See Also<a class="headerlink" title="Permalink to this headline" href="#See%20Also">¶</a></h2><p>
e735f4d4
MP
103 <a href="systemd.html"><span class="citerefentry"><span class="refentrytitle">systemd</span>(1)</span></a>,
104 <a href="systemd.journal-fields.html"><span class="citerefentry"><span class="refentrytitle">systemd.journal-fields</span>(7)</span></a>,
105 <a href="sd-journal.html"><span class="citerefentry"><span class="refentrytitle">sd-journal</span>(3)</span></a>,
106 <a href="sd_journal_open.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_open</span>(3)</span></a>,
107 <a href="sd_journal_next.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_next</span>(3)</span></a>,
108 <a href="sd_journal_get_realtime_usec.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_get_realtime_usec</span>(3)</span></a>,
109 <a href="sd_journal_query_unique.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_query_unique</span>(3)</span></a>
110 </p></div></div></body></html>