]>
Commit | Line | Data |
---|---|---|
663996b3 MS |
1 | <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>sd_journal_next</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>· | |
14228c0d | 22 | <a href="../libudev/index.html">gudev </a><span style="float:right">systemd 208</span><hr><div class="refentry"><a name="sd_journal_next"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>sd_journal_next, sd_journal_previous, sd_journal_next_skip, sd_journal_previous_skip, SD_JOURNAL_FOREACH, SD_JOURNAL_FOREACH_BACKWARDS — Advance or set back the read pointer in 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_next</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">int <b class="fsfunc">sd_journal_previous</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">int <b class="fsfunc">sd_journal_next_skip</b>(</code></td><td>sd_journal* <var class="pdparam">j</var>, </td></tr><tr><td> </td><td>uint64_t <var class="pdparam">skip</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_previous_skip</b>(</code></td><td>sd_journal* <var class="pdparam">j</var>, </td></tr><tr><td> </td><td>uint64_t <var class="pdparam">skip</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</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_BACKWARDS</b>(</code></td><td>sd_journal* <var class="pdparam">j</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a name="idm274688721504"></a><h2 id="Description">Description<a class="headerlink" title="Permalink to this headline" href="#Description">¶</a></h2><p><code class="function">sd_journal_next()</code> advances |
663996b3 MS |
23 | the read pointer into the journal by one entry. The |
24 | only argument taken is a journal context object as | |
25 | allocated via | |
26 | <a href="sd_journal_open.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_open</span>(3)</span></a>. After | |
27 | successful invocation the entry may be read with | |
28 | functions such as | |
29 | <a href="sd_journal_get_data.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_get_data</span>(3)</span></a>.</p><p>Similar, <code class="function">sd_journal_previous()</code> sets | |
30 | the read pointer back one entry.</p><p><code class="function">sd_journal_next_skip()</code> and | |
31 | <code class="function">sd_journal_previous_skip()</code> | |
32 | advance/set back the read pointer by multiple entries | |
33 | at once, as specified in the <code class="varname">skip</code> | |
34 | parameter.</p><p>The journal is strictly ordered by reception | |
35 | time, and hence advancing to the next entry guarantees | |
36 | that the entry then pointing to is later in time than | |
37 | then previous one, or has the same timestamp.</p><p>Note that | |
38 | <a href="sd_journal_get_data.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_get_data</span>(3)</span></a> | |
39 | and related calls will fail unless | |
40 | <code class="function">sd_journal_next()</code> has been | |
41 | invoked at least once in order to position the read | |
42 | pointer on a journal entry.</p><p>Note that the | |
43 | <code class="function">SD_JOURNAL_FOREACH()</code> macro may be used | |
44 | as a wrapper around | |
45 | <a href="sd_journal_seek_head.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_seek_head</span>(3)</span></a> | |
46 | and <code class="function">sd_journal_next()</code> in order to | |
47 | make iterating through the journal easier. See below | |
48 | for an example. Similar, | |
49 | <code class="function">SD_JOURNAL_FOREACH_BACKWARDS()</code> | |
50 | may be used for iterating the journal in reverse | |
14228c0d | 51 | order.</p></div><div class="refsect1"><a name="idm274688708112"></a><h2 id="Return Value">Return Value<a class="headerlink" title="Permalink to this headline" href="#Return%20Value">¶</a></h2><p>The four calls return the number of entries |
663996b3 MS |
52 | advanced/set back on success or a negative errno-style |
53 | error code. When the end or beginning of the journal | |
54 | is reached, a number smaller than requested is | |
55 | returned. More specifically, if | |
56 | <code class="function">sd_journal_next()</code> or | |
57 | <code class="function">sd_journal_previous()</code> reach the | |
58 | end/beginning of the journal they will return 0, | |
59 | instead of 1 when they are successful. This should be | |
14228c0d | 60 | considered an EOF marker.</p></div><div class="refsect1"><a name="idm274688698112"></a><h2 id="Notes">Notes<a class="headerlink" title="Permalink to this headline" href="#Notes">¶</a></h2><p>The <code class="function">sd_journal_next()</code>, <code class="function">sd_journal_previous()</code>, |
663996b3 MS |
61 | <code class="function">sd_journal_next_skip()</code> and |
62 | <code class="function">sd_journal_previous_skip()</code> interfaces are | |
63 | available as shared library, which can be compiled and | |
64 | linked to with the | |
14228c0d MB |
65 | <code class="constant">libsystemd-journal</code> <a href="pkg-config.html"><span class="citerefentry"><span class="refentrytitle">pkg-config</span>(1)</span></a> |
66 | file.</p></div><div class="refsect1"><a name="idm274688692528"></a><h2 id="Examples">Examples<a class="headerlink" title="Permalink to this headline" href="#Examples">¶</a></h2><p>Iterating through the journal:</p><pre class="programlisting">#include <stdio.h> | |
663996b3 MS |
67 | #include <string.h> |
68 | #include <systemd/sd-journal.h> | |
69 | ||
70 | int main(int argc, char *argv[]) { | |
71 | int r; | |
72 | sd_journal *j; | |
73 | r = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY); | |
74 | if (r < 0) { | |
75 | fprintf(stderr, "Failed to open journal: %s\n", strerror(-r)); | |
76 | return 1; | |
77 | } | |
78 | SD_JOURNAL_FOREACH(j) { | |
79 | const char *d; | |
80 | size_t l; | |
81 | ||
82 | r = sd_journal_get_data(j, "MESSAGE", &d, &l); | |
83 | if (r < 0) { | |
84 | fprintf(stderr, "Failed to read message field: %s\n", strerror(-r)); | |
85 | continue; | |
86 | } | |
87 | ||
88 | printf("%.*s\n", (int) l, d); | |
89 | } | |
90 | sd_journal_close(j); | |
91 | return 0; | |
14228c0d | 92 | }</pre></div><div class="refsect1"><a name="idm274688689024"></a><h2 id="See Also">See Also<a class="headerlink" title="Permalink to this headline" href="#See%20Also">¶</a></h2><p> |
663996b3 MS |
93 | <a href="systemd.html"><span class="citerefentry"><span class="refentrytitle">systemd</span>(1)</span></a>, |
94 | <a href="sd-journal.html"><span class="citerefentry"><span class="refentrytitle">sd-journal</span>(3)</span></a>, | |
95 | <a href="sd_journal_open.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_open</span>(3)</span></a>, | |
96 | <a href="sd_journal_get_data.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_get_data</span>(3)</span></a>, | |
97 | <a href="sd_journal_get_realtime_usec.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_get_realtime_usec</span>(3)</span></a>, | |
98 | <a href="sd_journal_get_cursor.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_get_cursor</span>(3)</span></a> | |
99 | </p></div></div></body></html> |