]>
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>· | |
e3bff60a | 22 | <a href="../libudev/index.html">gudev </a><span style="float:right">systemd 220</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="idm140486858675120"></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 the read |
e735f4d4 MP |
23 | pointer into the journal by one entry. The only argument taken is |
24 | a journal context object as allocated via | |
25 | <a href="sd_journal_open.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_open</span>(3)</span></a>. | |
26 | After successful invocation the entry may be read with functions | |
27 | such as | |
28 | <a href="sd_journal_get_data.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_get_data</span>(3)</span></a>.</p><p>Similarly, <code class="function">sd_journal_previous()</code> sets | |
29 | the read pointer back one entry.</p><p><code class="function">sd_journal_next_skip()</code> and | |
30 | <code class="function">sd_journal_previous_skip()</code> advance/set back | |
31 | the read pointer by multiple entries at once, as specified in the | |
32 | <code class="varname">skip</code> parameter.</p><p>The journal is strictly ordered by reception time, and hence | |
33 | advancing to the next entry guarantees that the entry then | |
34 | pointing to is later in time than then previous one, or has the | |
35 | same timestamp.</p><p>Note that | |
36 | <a href="sd_journal_get_data.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_get_data</span>(3)</span></a> | |
37 | and related calls will fail unless | |
38 | <code class="function">sd_journal_next()</code> has been invoked at least | |
39 | once in order to position the read pointer on a journal | |
40 | entry.</p><p>Note that the <code class="function">SD_JOURNAL_FOREACH()</code> | |
41 | macro may be used as a wrapper around | |
42 | <a href="sd_journal_seek_head.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_seek_head</span>(3)</span></a> | |
43 | and <code class="function">sd_journal_next()</code> in order to make | |
44 | iterating through the journal easier. See below for an example. | |
45 | Similarly, <code class="function">SD_JOURNAL_FOREACH_BACKWARDS()</code> may | |
e3bff60a | 46 | be used for iterating the journal in reverse order.</p></div><div class="refsect1"><a name="idm140486854036752"></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 advanced/set |
e735f4d4 MP |
47 | back on success or a negative errno-style error code. When the end |
48 | or beginning of the journal is reached, a number smaller than | |
49 | requested is returned. More specifically, if | |
50 | <code class="function">sd_journal_next()</code> or | |
51 | <code class="function">sd_journal_previous()</code> reach the end/beginning | |
52 | of the journal they will return 0, instead of 1 when they are | |
e3bff60a | 53 | successful. This should be considered an EOF marker.</p></div><div class="refsect1"><a name="idm140486854033936"></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>, |
e735f4d4 MP |
54 | <code class="function">sd_journal_previous()</code>, |
55 | <code class="function">sd_journal_next_skip()</code> and | |
56 | <code class="function">sd_journal_previous_skip()</code> interfaces are | |
57 | available as a shared library, which can be compiled and linked to | |
58 | with the | |
59 | <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 | 60 | file.</p></div><div class="refsect1"><a name="idm140486854028768"></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 |
61 | #include <string.h> |
62 | #include <systemd/sd-journal.h> | |
63 | ||
64 | int main(int argc, char *argv[]) { | |
e735f4d4 MP |
65 | int r; |
66 | sd_journal *j; | |
67 | r = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY); | |
68 | if (r < 0) { | |
69 | fprintf(stderr, "Failed to open journal: %s\n", strerror(-r)); | |
70 | return 1; | |
71 | } | |
72 | SD_JOURNAL_FOREACH(j) { | |
73 | const char *d; | |
74 | size_t l; | |
663996b3 | 75 | |
e735f4d4 MP |
76 | r = sd_journal_get_data(j, "MESSAGE", (const void **)&d, &l); |
77 | if (r < 0) { | |
78 | fprintf(stderr, "Failed to read message field: %s\n", strerror(-r)); | |
79 | continue; | |
80 | } | |
663996b3 | 81 | |
e735f4d4 MP |
82 | printf("%.*s\n", (int) l, d); |
83 | } | |
84 | sd_journal_close(j); | |
85 | return 0; | |
e3bff60a | 86 | }</pre></div><div class="refsect1"><a name="idm140486854026144"></a><h2 id="See Also">See Also<a class="headerlink" title="Permalink to this headline" href="#See%20Also">¶</a></h2><p> |
e735f4d4 MP |
87 | <a href="systemd.html"><span class="citerefentry"><span class="refentrytitle">systemd</span>(1)</span></a>, |
88 | <a href="sd-journal.html"><span class="citerefentry"><span class="refentrytitle">sd-journal</span>(3)</span></a>, | |
89 | <a href="sd_journal_open.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_open</span>(3)</span></a>, | |
90 | <a href="sd_journal_get_data.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_get_data</span>(3)</span></a>, | |
91 | <a href="sd_journal_get_realtime_usec.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_get_realtime_usec</span>(3)</span></a>, | |
92 | <a href="sd_journal_get_cursor.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_get_cursor</span>(3)</span></a> | |
93 | </p></div></div></body></html> |