~ubuntu-branches/ubuntu/trusty/systemd/trusty

« back to all changes in this revision

Viewing changes to man/sd_journal_next_skip.html

Tags: upstream-202
Import upstream version 202

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.77.1"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><a href="index.html">Index </a>·
 
2
  <a href="systemd.directives.html">Directives </a>·
 
3
  <a href="../python-systemd/index.html">Python </a>·
 
4
  <a href="../libudev/index.html">libudev </a>·
 
5
  <a href="../libudev/index.html">gudev </a><span style="float:right">systemd 202</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 &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_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="idp26192"></a><h2>Description</h2><p><code class="function">sd_journal_next()</code> advances
 
6
                the read pointer into the journal by one entry. The
 
7
                only argument taken is a journal context object as
 
8
                allocated via
 
9
                <a href="sd_journal_open.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_open</span>(3)</span></a>. After
 
10
                successful invocation the entry may be read with
 
11
                functions such as
 
12
                <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
 
13
                the read pointer back one entry.</p><p><code class="function">sd_journal_next_skip()</code> and
 
14
                <code class="function">sd_journal_previous_skip()</code>
 
15
                advance/set back the read pointer by multiple entries
 
16
                at once, as specified in the <code class="varname">skip</code>
 
17
                parameter.</p><p>The journal is strictly ordered by reception
 
18
                time, and hence advancing to the next entry guarantees
 
19
                that the entry then pointing to is later in time than
 
20
                then previous one, or has the same timestamp.</p><p>Note that
 
21
                <a href="sd_journal_get_data.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_get_data</span>(3)</span></a>
 
22
                and related calls will fail unless
 
23
                <code class="function">sd_journal_next()</code> has been
 
24
                invoked at least once in order to position the read
 
25
                pointer on a journal entry.</p><p>Note that the
 
26
                <code class="function">SD_JOURNAL_FOREACH()</code> macro may be used
 
27
                as a wrapper around
 
28
                <a href="sd_journal_seek_head.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_seek_head</span>(3)</span></a>
 
29
                and <code class="function">sd_journal_next()</code> in order to
 
30
                make iterating through the journal easier. See below
 
31
                for an example. Similar,
 
32
                <code class="function">SD_JOURNAL_FOREACH_BACKWARDS()</code>
 
33
                may be used for iterating the journal in reverse
 
34
                order.</p></div><div class="refsect1"><a name="idp39584"></a><h2>Return Value</h2><p>The four calls return the number of entries
 
35
                advanced/set back on success or a negative errno-style
 
36
                error code. When the end or beginning of the journal
 
37
                is reached, a number smaller than requested is
 
38
                returned. More specifically, if
 
39
                <code class="function">sd_journal_next()</code> or
 
40
                <code class="function">sd_journal_previous()</code> reach the
 
41
                end/beginning of the journal they will return 0,
 
42
                instead of 1 when they are successful. This should be
 
43
                considered an EOF marker.</p></div><div class="refsect1"><a name="idp49696"></a><h2>Notes</h2><p>The <code class="function">sd_journal_next()</code>, <code class="function">sd_journal_previous()</code>,
 
44
                <code class="function">sd_journal_next_skip()</code> and
 
45
                <code class="function">sd_journal_previous_skip()</code> interfaces are
 
46
                available as shared library, which can be compiled and
 
47
                linked to with the
 
48
                <code class="literal">libsystemd-journal</code>
 
49
                <a href="pkg-config.html"><span class="citerefentry"><span class="refentrytitle">pkg-config</span>(1)</span></a>
 
50
                file.</p></div><div class="refsect1"><a name="idp55520"></a><h2>Examples</h2><p>Iterating through the journal:</p><pre class="programlisting">#include &lt;stdio.h&gt;
 
51
#include &lt;string.h&gt;
 
52
#include &lt;systemd/sd-journal.h&gt;
 
53
 
 
54
int main(int argc, char *argv[]) {
 
55
        int r;
 
56
        sd_journal *j;
 
57
        r = sd_journal_open(&amp;j, SD_JOURNAL_LOCAL_ONLY);
 
58
        if (r &lt; 0) {
 
59
                fprintf(stderr, "Failed to open journal: %s\n", strerror(-r));
 
60
                return 1;
 
61
        }
 
62
        SD_JOURNAL_FOREACH(j) {
 
63
                const char *d;
 
64
                size_t l;
 
65
 
 
66
                r = sd_journal_get_data(j, "MESSAGE", &amp;d, &amp;l);
 
67
                if (r &lt; 0) {
 
68
                        fprintf(stderr, "Failed to read message field: %s\n", strerror(-r));
 
69
                        continue;
 
70
                }
 
71
 
 
72
                printf("%.*s\n", (int) l, d);
 
73
        }
 
74
        sd_journal_close(j);
 
75
        return 0;
 
76
}</pre></div><div class="refsect1"><a name="idp59024"></a><h2>See Also</h2><p>
 
77
                        <a href="systemd.html"><span class="citerefentry"><span class="refentrytitle">systemd</span>(1)</span></a>,
 
78
                        <a href="sd-journal.html"><span class="citerefentry"><span class="refentrytitle">sd-journal</span>(3)</span></a>,
 
79
                        <a href="sd_journal_open.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_open</span>(3)</span></a>,
 
80
                        <a href="sd_journal_get_data.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_get_data</span>(3)</span></a>,
 
81
                        <a href="sd_journal_get_realtime_usec.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_get_realtime_usec</span>(3)</span></a>,
 
82
                        <a href="sd_journal_get_cursor.html"><span class="citerefentry"><span class="refentrytitle">sd_journal_get_cursor</span>(3)</span></a>
 
83
                </p></div></div></body></html>