sd_journal_get_data.html 12.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
<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>
    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>·
22
  <a href="../libudev/index.html">gudev </a><span style="float:right">systemd 215</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="idm214182872080"></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
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
                the data object associated with a specific field from
                the current journal entry. It takes four arguments:
                the journal context object, a string with the field
                name to request, plus a pair of pointers to
                pointer/size variables where the data object and its
                size shall be stored in. The field name should be an
                entry field name. Well-known field names are listed in
                <a href="systemd.journal-fields.html"><span class="citerefentry"><span class="refentrytitle">systemd.journal-fields</span>(7)</span></a>. The
                returned data is in a read-only memory map and is only
                valid until the next invocation of
                <code class="function">sd_journal_get_data()</code> or
                <code class="function">sd_journal_enumerate_data()</code>, or
                the read pointer is altered. Note that the data
                returned will be prefixed with the field name and
                '='. Also note that by default data fields larger than
                64K might get truncated to 64K. This threshold may be
                changed and turned off with
                <code class="function">sd_journal_set_data_threshold()</code> (see
                below).</p><p><code class="function">sd_journal_enumerate_data()</code>
                may be used to iterate through all fields of the
                current entry. On each invocation the data for the
                next field is returned. The order of these fields is
                not defined. The data returned is in the same format
                as with <code class="function">sd_journal_get_data()</code> and
                also follows the same life-time semantics.</p><p><code class="function">sd_journal_restart_data()</code>
                resets the data enumeration index to the beginning of
                the entry. The next invocation of
                <code class="function">sd_journal_enumerate_data()</code> will return the first
                field of the entry again.</p><p>Note that the
                <code class="function">SD_JOURNAL_FOREACH_DATA()</code> macro
                may be used as a handy wrapper around
                <code class="function">sd_journal_restart_data()</code> and
                <code class="function">sd_journal_enumerate_data()</code>.</p><p>Note that these functions will not work before
                <a href="sd_journal_next.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_next</span>(3)</span></a>
                (or related call) has been called at least
                once, in order to position the read pointer at a valid entry.</p><p><code class="function">sd_journal_set_data_threshold()</code>
                may be used to change the data field size threshold
                for data returned by
                <code class="function">sd_journal_get_data()</code>,
                <code class="function">sd_journal_enumerate_data()</code> and
                <code class="function">sd_journal_enumerate_unique()</code>. This
                threshold is a hint only: it indicates that the client
                program is interested only in the initial parts of the
                data fields, up to the threshold in size -- but the
                library might still return larger data objects. That
                means applications should not rely exclusively on this
                setting to limit the size of the data fields returned,
                but need to apply a explicit size limit on the
                returned data as well. This threshold defaults to 64K
                by default. To retrieve the complete data fields this
                threshold should be turned off by setting it to 0, so
                that the library always returns the complete data
                objects. It is recommended to set this threshold as
                low as possible since this relieves the library from
                having to decompress large compressed data objects in
                full.</p><p><code class="function">sd_journal_get_data_threshold()</code>
                returns the currently configured data field size
80
                threshold.</p></div><div class="refsect1"><a name="idm214182845904"></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>
81 82
                returns 0 on success or a negative errno-style error
                code. If the current entry does not include the
83
                specified field, -ENOENT is returned. If
84
                <a href="sd_journal_next.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_next</span>(3)</span></a>
85
                has not been called at least once, -EADDRNOTAVAIL is
86 87 88 89 90 91 92 93 94
                returned. <code class="function">sd_journal_enumerate_data()</code>
                returns a positive integer if the next field has been
                read, 0 when no more fields are known, or a negative
                errno-style error
                code. <code class="function">sd_journal_restart_data()</code>
                returns
                nothing. <code class="function">sd_journal_set_data_threshold()</code>
                and <code class="function">sd_journal_get_threshold()</code>
                return 0 on success or a negative errno-style error
95
                code.</p></div><div class="refsect1"><a name="idm214182839856"></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>,
96 97 98 99 100
                <code class="function">sd_journal_enumerate_data()</code>,
                <code class="function">sd_journal_restart_data()</code>,
                <code class="function">sd_journal_set_data_threshold()</code>
                and
                <code class="function">sd_journal_get_data_threshold()</code>
101
                interfaces are available as a shared library, which can
102
                be compiled and linked to with the
103
                <code class="constant">libsystemd</code> <a href="pkg-config.html"><span class="citerefentry"><span class="refentrytitle">pkg-config</span>(1)</span></a>
104
                file.</p></div><div class="refsect1"><a name="idm214177917392"></a><h2 id="Examples">Examples<a class="headerlink" title="Permalink to this headline" href="#Examples"></a></h2><p>See
105 106 107 108 109 110 111 112
                <a href="sd_journal_next.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_next</span>(3)</span></a>
                for a complete example how to use
                <code class="function">sd_journal_get_data()</code>.</p><p>Use the
                <code class="function">SD_JOURNAL_FOREACH_DATA</code> macro to
                iterate through all fields of the current journal
                entry:</p><pre class="programlisting">...
int print_fields(sd_journal *j) {
        const void *data;
113
        size_t length;
114 115 116
        SD_JOURNAL_FOREACH_DATA(j, data, length)
                printf("%.*s\n", (int) length, data);
}
117
...</pre></div><div class="refsect1"><a name="idm214177912896"></a><h2 id="See Also">See Also<a class="headerlink" title="Permalink to this headline" href="#See%20Also"></a></h2><p>
118 119 120 121 122 123 124 125
                        <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_next.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_next</span>(3)</span></a>,
                        <a href="sd_journal_get_realtime_usec.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_get_realtime_usec</span>(3)</span></a>,
                        <a href="sd_journal_query_unique.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_query_unique</span>(3)</span></a>
                </p></div></div></body></html>