]>
Commit | Line | Data |
---|---|---|
14228c0d | 1 | '\" t |
5eef597e | 2 | .TH "SD_JOURNAL_NEXT" "3" "" "systemd 217" "sd_journal_next" |
14228c0d MB |
3 | .\" ----------------------------------------------------------------- |
4 | .\" * Define some portability stuff | |
5 | .\" ----------------------------------------------------------------- | |
6 | .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
7 | .\" http://bugs.debian.org/507673 | |
8 | .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html | |
9 | .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
10 | .ie \n(.g .ds Aq \(aq | |
11 | .el .ds Aq ' | |
12 | .\" ----------------------------------------------------------------- | |
13 | .\" * set default formatting | |
14 | .\" ----------------------------------------------------------------- | |
15 | .\" disable hyphenation | |
16 | .nh | |
17 | .\" disable justification (adjust text to left margin only) | |
18 | .ad l | |
19 | .\" ----------------------------------------------------------------- | |
20 | .\" * MAIN CONTENT STARTS HERE * | |
21 | .\" ----------------------------------------------------------------- | |
22 | .SH "NAME" | |
23 | 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 | |
24 | .SH "SYNOPSIS" | |
25 | .sp | |
26 | .ft B | |
27 | .nf | |
28 | #include <systemd/sd\-journal\&.h> | |
29 | .fi | |
30 | .ft | |
31 | .HP \w'int\ sd_journal_next('u | |
60f067b4 | 32 | .BI "int sd_journal_next(sd_journal\ *" "j" ");" |
14228c0d | 33 | .HP \w'int\ sd_journal_previous('u |
60f067b4 | 34 | .BI "int sd_journal_previous(sd_journal\ *" "j" ");" |
14228c0d | 35 | .HP \w'int\ sd_journal_next_skip('u |
60f067b4 | 36 | .BI "int sd_journal_next_skip(sd_journal\ *" "j" ", uint64_t\ " "skip" ");" |
14228c0d | 37 | .HP \w'int\ sd_journal_previous_skip('u |
60f067b4 | 38 | .BI "int sd_journal_previous_skip(sd_journal\ *" "j" ", uint64_t\ " "skip" ");" |
14228c0d | 39 | .HP \w'SD_JOURNAL_FOREACH('u |
60f067b4 | 40 | .BI "SD_JOURNAL_FOREACH(sd_journal\ *" "j" ");" |
14228c0d | 41 | .HP \w'SD_JOURNAL_FOREACH_BACKWARDS('u |
60f067b4 | 42 | .BI "SD_JOURNAL_FOREACH_BACKWARDS(sd_journal\ *" "j" ");" |
14228c0d MB |
43 | .SH "DESCRIPTION" |
44 | .PP | |
45 | \fBsd_journal_next()\fR | |
46 | advances the read pointer into the journal by one entry\&. The only argument taken is a journal context object as allocated via | |
47 | \fBsd_journal_open\fR(3)\&. After successful invocation the entry may be read with functions such as | |
48 | \fBsd_journal_get_data\fR(3)\&. | |
49 | .PP | |
60f067b4 | 50 | Similarly, |
14228c0d MB |
51 | \fBsd_journal_previous()\fR |
52 | sets the read pointer back one entry\&. | |
53 | .PP | |
54 | \fBsd_journal_next_skip()\fR | |
55 | and | |
56 | \fBsd_journal_previous_skip()\fR | |
57 | advance/set back the read pointer by multiple entries at once, as specified in the | |
58 | \fIskip\fR | |
59 | parameter\&. | |
60 | .PP | |
61 | The journal is strictly ordered by reception time, and hence advancing to the next entry guarantees that the entry then pointing to is later in time than then previous one, or has the same timestamp\&. | |
62 | .PP | |
63 | Note that | |
64 | \fBsd_journal_get_data\fR(3) | |
65 | and related calls will fail unless | |
66 | \fBsd_journal_next()\fR | |
67 | has been invoked at least once in order to position the read pointer on a journal entry\&. | |
68 | .PP | |
69 | Note that the | |
70 | \fBSD_JOURNAL_FOREACH()\fR | |
71 | macro may be used as a wrapper around | |
72 | \fBsd_journal_seek_head\fR(3) | |
73 | and | |
74 | \fBsd_journal_next()\fR | |
60f067b4 | 75 | in order to make iterating through the journal easier\&. See below for an example\&. Similarly, |
14228c0d MB |
76 | \fBSD_JOURNAL_FOREACH_BACKWARDS()\fR |
77 | may be used for iterating the journal in reverse order\&. | |
78 | .SH "RETURN VALUE" | |
79 | .PP | |
80 | The four calls return the number of entries advanced/set back on success or a negative errno\-style error code\&. When the end or beginning of the journal is reached, a number smaller than requested is returned\&. More specifically, if | |
81 | \fBsd_journal_next()\fR | |
82 | or | |
83 | \fBsd_journal_previous()\fR | |
84 | reach the end/beginning of the journal they will return 0, instead of 1 when they are successful\&. This should be considered an EOF marker\&. | |
85 | .SH "NOTES" | |
86 | .PP | |
87 | The | |
88 | \fBsd_journal_next()\fR, | |
89 | \fBsd_journal_previous()\fR, | |
90 | \fBsd_journal_next_skip()\fR | |
91 | and | |
92 | \fBsd_journal_previous_skip()\fR | |
60f067b4 JS |
93 | interfaces are available as a shared library, which can be compiled and linked to with the |
94 | \fBlibsystemd\fR\ \&\fBpkg-config\fR(1) | |
14228c0d MB |
95 | file\&. |
96 | .SH "EXAMPLES" | |
97 | .PP | |
98 | Iterating through the journal: | |
99 | .sp | |
100 | .if n \{\ | |
101 | .RS 4 | |
102 | .\} | |
103 | .nf | |
104 | #include <stdio\&.h> | |
105 | #include <string\&.h> | |
106 | #include <systemd/sd\-journal\&.h> | |
107 | ||
108 | int main(int argc, char *argv[]) { | |
109 | int r; | |
110 | sd_journal *j; | |
111 | r = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY); | |
112 | if (r < 0) { | |
113 | fprintf(stderr, "Failed to open journal: %s\en", strerror(\-r)); | |
114 | return 1; | |
115 | } | |
116 | SD_JOURNAL_FOREACH(j) { | |
117 | const char *d; | |
118 | size_t l; | |
119 | ||
e842803a | 120 | r = sd_journal_get_data(j, "MESSAGE", (const void **)&d, &l); |
14228c0d MB |
121 | if (r < 0) { |
122 | fprintf(stderr, "Failed to read message field: %s\en", strerror(\-r)); | |
123 | continue; | |
124 | } | |
125 | ||
126 | printf("%\&.*s\en", (int) l, d); | |
127 | } | |
128 | sd_journal_close(j); | |
129 | return 0; | |
130 | } | |
131 | .fi | |
132 | .if n \{\ | |
133 | .RE | |
134 | .\} | |
135 | .SH "SEE ALSO" | |
136 | .PP | |
137 | \fBsystemd\fR(1), | |
138 | \fBsd-journal\fR(3), | |
139 | \fBsd_journal_open\fR(3), | |
140 | \fBsd_journal_get_data\fR(3), | |
141 | \fBsd_journal_get_realtime_usec\fR(3), | |
142 | \fBsd_journal_get_cursor\fR(3) |