Debian Codegraph @

upstream/debian-unstable/man3/sd_journal_next.3

raw
1 '\" t
2 .TH "SD_JOURNAL_NEXT" "3" "" "systemd 261~rc3" "sd_journal_next"
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_step_one, 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
32 .BI "int sd_journal_next(sd_journal\ *" "j" ");"
33 .HP \w'int\ sd_journal_previous('u
34 .BI "int sd_journal_previous(sd_journal\ *" "j" ");"
35 .HP \w'int\ sd_journal_step_one('u
36 .BI "int sd_journal_step_one(sd_journal\ *" "j" ", int\ " "advanced" ");"
37 .HP \w'int\ sd_journal_next_skip('u
38 .BI "int sd_journal_next_skip(sd_journal\ *" "j" ", uint64_t\ " "skip" ");"
39 .HP \w'int\ sd_journal_previous_skip('u
40 .BI "int sd_journal_previous_skip(sd_journal\ *" "j" ", uint64_t\ " "skip" ");"
41 .HP \w'SD_JOURNAL_FOREACH('u
42 .BI "SD_JOURNAL_FOREACH(sd_journal\ *" "j" ");"
43 .HP \w'SD_JOURNAL_FOREACH_BACKWARDS('u
44 .BI "SD_JOURNAL_FOREACH_BACKWARDS(sd_journal\ *" "j" ");"
45 .SH "DESCRIPTION"
46 .PP
47 \fBsd_journal_next()\fR
48 advances the read pointer into the journal by one entry\&. The only argument taken is a journal context object as allocated via
49 \fBsd_journal_open\fR(3)\&. After successful invocation the entry may be read with functions such as
50 \fBsd_journal_get_data\fR(3)\&.
51 .PP
52 Similarly,
53 \fBsd_journal_previous()\fR
54 sets the read pointer back one entry\&.
55 .PP
56 \fBsd_journal_step_one()\fR
57 also moves the read pointer\&. If the current location is the head of the journal, e\&.g\&. when this is called following
58 \fBsd_journal_seek_head()\fR, then this is equivalent to
59 \fBsd_journal_next()\fR, and the argument
60 \fIadvanced\fR
61 will be ignored\&. Similarly, if the current location is the tail of the journal, e\&.g\&. when this is called following
62 \fBsd_journal_seek_tail()\fR, then this is equivalent to
63 \fBsd_journal_previous()\fR, and
64 \fIadvanced\fR
65 will be ignored\&. Otherwise, this is equivalent to
66 \fBsd_journal_next()\fR
67 when
68 \fIadvanced\fR
69 is non\-zero, and
70 \fBsd_journal_previous()\fR
71 when
72 \fIadvanced\fR
73 is zero\&.
74 .PP
75 \fBsd_journal_next_skip()\fR
76 and
77 \fBsd_journal_previous_skip()\fR
78 advance/set back the read pointer by multiple entries at once, as specified in the
79 \fIskip\fR
80 parameter\&. The
81 \fIskip\fR
82 parameter must be less than or equal to 2147483647 (2\(S3\(S1\-1)\&.
83 .PP
84 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\&.
85 .PP
86 Note that
87 \fBsd_journal_get_data\fR(3)
88 and related calls will fail unless
89 \fBsd_journal_next()\fR
90 has been invoked at least once in order to position the read pointer on a journal entry\&.
91 .PP
92 Note that the
93 \fBSD_JOURNAL_FOREACH()\fR
94 macro may be used as a wrapper around
95 \fBsd_journal_seek_head\fR(3)
96 and
97 \fBsd_journal_next()\fR
98 in order to make iterating through the journal easier\&. See below for an example\&. Similarly,
99 \fBSD_JOURNAL_FOREACH_BACKWARDS()\fR
100 may be used for iterating the journal in reverse order\&.
101 .SH "RETURN VALUE"
102 .PP
103 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
104 \fBsd_journal_next()\fR
105 or
106 \fBsd_journal_previous()\fR
107 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\&.
108 .SH "NOTES"
109 .PP
110 All functions listed here are thread\-agnostic and only a single thread may operate on a given object at any given time\&. Different threads may access the same object at different times\&. Multiple independent objects may be used from different threads in parallel\&.
111 .PP
112 Functions described here are available as a shared library, which can be compiled against and linked to with the
113 \fBlibsystemd\fR\ \&\fBpkg-config\fR(1)
114 file\&.
115 .SH "EXAMPLES"
116 .PP
117 Iterating through the journal:
118 .sp
119 .if n \{\
120 .RS 4
121 .\}
122 .nf
123 /* SPDX\-License\-Identifier: MIT\-0 */
124
125 #include <errno\&.h>
126 #include <stdio\&.h>
127 #include <systemd/sd\-journal\&.h>
128
129 int main(int argc, char *argv[]) {
130 int r;
131 sd_journal *j;
132
133 r = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY);
134 if (r < 0) {
135 fprintf(stderr, "Failed to open journal: %s\en", strerror(\-r));
136 return 1;
137 }
138 SD_JOURNAL_FOREACH(j) {
139 const char *d;
140 size_t l;
141
142 r = sd_journal_get_data(j, "MESSAGE", (const void **)&d, &l);
143 if (r < 0) {
144 fprintf(stderr, "Failed to read message field: %s\en", strerror(\-r));
145 continue;
146 }
147
148 printf("%\&.*s\en", (int) l, d);
149 }
150 sd_journal_close(j);
151 return 0;
152 }
153 .fi
154 .if n \{\
155 .RE
156 .\}
157 .SH "HISTORY"
158 .PP
159 \fBsd_journal_next()\fR,
160 \fBsd_journal_previous()\fR,
161 \fBsd_journal_next_skip()\fR,
162 \fBsd_journal_previous_skip()\fR,
163 \fBSD_JOURNAL_FOREACH()\fR, and
164 \fBSD_JOURNAL_FOREACH_BACKWARDS()\fR
165 were added in version 187\&.
166 .PP
167 \fBsd_journal_step_one()\fR
168 was added in version 254\&.
169 .SH "SEE ALSO"
170 .PP
171 \fBsystemd\fR(1), \fBsd-journal\fR(3), \fBsd_journal_open\fR(3), \fBsd_journal_get_data\fR(3), \fBsd_journal_get_realtime_usec\fR(3), \fBsd_journal_get_cursor\fR(3)