]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/sd_journal_open.xml
Merge pull request #4509 from keszybz/foreach-word-quoted
[thirdparty/systemd.git] / man / sd_journal_open.xml
CommitLineData
3bb55eee
LP
1<?xml version='1.0'?> <!--*-nxml-*-->
2<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
12b42c76 3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
3bb55eee
LP
4
5<!--
6 This file is part of systemd.
7
8 Copyright 2012 Lennart Poettering
9
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22-->
23
24<refentry id="sd_journal_open">
25
798d3a52
ZJS
26 <refentryinfo>
27 <title>sd_journal_open</title>
28 <productname>systemd</productname>
29
30 <authorgroup>
31 <author>
32 <contrib>Developer</contrib>
33 <firstname>Lennart</firstname>
34 <surname>Poettering</surname>
35 <email>lennart@poettering.net</email>
36 </author>
37 </authorgroup>
38 </refentryinfo>
39
40 <refmeta>
41 <refentrytitle>sd_journal_open</refentrytitle>
42 <manvolnum>3</manvolnum>
43 </refmeta>
44
45 <refnamediv>
46 <refname>sd_journal_open</refname>
47 <refname>sd_journal_open_directory</refname>
2aab2fab 48 <refname>sd_journal_open_directory_fd</refname>
798d3a52 49 <refname>sd_journal_open_files</refname>
2aab2fab 50 <refname>sd_journal_open_files_fd</refname>
798d3a52
ZJS
51 <refname>sd_journal_close</refname>
52 <refname>sd_journal</refname>
53 <refname>SD_JOURNAL_LOCAL_ONLY</refname>
54 <refname>SD_JOURNAL_RUNTIME_ONLY</refname>
55 <refname>SD_JOURNAL_SYSTEM</refname>
56 <refname>SD_JOURNAL_CURRENT_USER</refname>
2aab2fab 57 <refname>SD_JOURNAL_OS_ROOT</refname>
798d3a52
ZJS
58 <refpurpose>Open the system journal for reading</refpurpose>
59 </refnamediv>
60
61 <refsynopsisdiv>
62 <funcsynopsis>
63 <funcsynopsisinfo>#include &lt;systemd/sd-journal.h&gt;</funcsynopsisinfo>
64
65 <funcprototype>
66 <funcdef>int <function>sd_journal_open</function></funcdef>
67 <paramdef>sd_journal **<parameter>ret</parameter></paramdef>
68 <paramdef>int <parameter>flags</parameter></paramdef>
69 </funcprototype>
70
71 <funcprototype>
72 <funcdef>int <function>sd_journal_open_directory</function></funcdef>
73 <paramdef>sd_journal **<parameter>ret</parameter></paramdef>
74 <paramdef>const char *<parameter>path</parameter></paramdef>
75 <paramdef>int <parameter>flags</parameter></paramdef>
76 </funcprototype>
77
2aab2fab
LP
78 <funcprototype>
79 <funcdef>int <function>sd_journal_open_directory_fd</function></funcdef>
80 <paramdef>sd_journal **<parameter>ret</parameter></paramdef>
81 <paramdef>int <parameter>fd</parameter></paramdef>
82 <paramdef>int <parameter>flags</parameter></paramdef>
83 </funcprototype>
84
798d3a52
ZJS
85 <funcprototype>
86 <funcdef>int <function>sd_journal_open_files</function></funcdef>
87 <paramdef>sd_journal **<parameter>ret</parameter></paramdef>
88 <paramdef>const char **<parameter>paths</parameter></paramdef>
89 <paramdef>int <parameter>flags</parameter></paramdef>
90 </funcprototype>
91
92 <funcprototype>
2aab2fab 93 <funcdef>int <function>sd_journal_open_files_fd</function></funcdef>
798d3a52 94 <paramdef>sd_journal **<parameter>ret</parameter></paramdef>
2aab2fab
LP
95 <paramdef>int <parameter>fds[]</parameter></paramdef>
96 <paramdef>unsigned <parameter>n_fds</parameter></paramdef>
798d3a52
ZJS
97 <paramdef>int <parameter>flags</parameter></paramdef>
98 </funcprototype>
99
100 <funcprototype>
101 <funcdef>void <function>sd_journal_close</function></funcdef>
102 <paramdef>sd_journal *<parameter>j</parameter></paramdef>
103 </funcprototype>
104 </funcsynopsis>
105 </refsynopsisdiv>
106
107 <refsect1>
108 <title>Description</title>
109
110 <para><function>sd_journal_open()</function> opens the log journal
111 for reading. It will find all journal files automatically and
112 interleave them automatically when reading. As first argument it
b938cb90
JE
113 takes a pointer to a <varname>sd_journal</varname> pointer, which,
114 on success, will contain a journal context object. The second
798d3a52
ZJS
115 argument is a flags field, which may consist of the following
116 flags ORed together: <constant>SD_JOURNAL_LOCAL_ONLY</constant>
117 makes sure only journal files generated on the local machine will
118 be opened. <constant>SD_JOURNAL_RUNTIME_ONLY</constant> makes sure
119 only volatile journal files will be opened, excluding those which
120 are stored on persistent storage.
121 <constant>SD_JOURNAL_SYSTEM</constant> will cause journal files of
122 system services and the kernel (in opposition to user session
123 processes) to be opened.
124 <constant>SD_JOURNAL_CURRENT_USER</constant> will cause journal
125 files of the current user to be opened. If neither
126 <constant>SD_JOURNAL_SYSTEM</constant> nor
127 <constant>SD_JOURNAL_CURRENT_USER</constant> are specified, all
128 journal file types will be opened.</para>
129
2aab2fab
LP
130 <para><function>sd_journal_open_directory()</function> is similar to <function>sd_journal_open()</function> but
131 takes an absolute directory path as argument. All journal files in this directory will be opened and interleaved
10752e82
ZJS
132 automatically. This call also takes a flags argument. The flags parameters accepted by this call are
133 <constant>SD_JOURNAL_OS_ROOT</constant>, <constant>SD_JOURNAL_SYSTEM</constant>, and
134 <constant>SD_JOURNAL_CURRENT_USER</constant>. If <constant>SD_JOURNAL_OS_ROOT</constant> is specified, journal
135 files are searched for below the usual <filename>/var/log/journal</filename> and
136 <filename>/run/log/journal</filename> relative to the specified path, instead of directly beneath it.
137 The other two flags limit which files are opened, the same as for <function>sd_journal_open()</function>.
138 </para>
2aab2fab
LP
139
140 <para><function>sd_journal_open_directory_fd()</function> is similar to
141 <function>sd_journal_open_directory()</function>, but takes a file descriptor referencing a directory in the file
142 system instead of an absolute file system path.</para>
143
144 <para><function>sd_journal_open_files()</function> is similar to <function>sd_journal_open()</function> but takes a
145 <constant>NULL</constant>-terminated list of file paths to open. All files will be opened and interleaved
146 automatically. This call also takes a flags argument, but it must be passed as 0 as no flags are currently
147 understood for this call. Please note that in the case of a live journal, this function is only useful for
148 debugging, because individual journal files can be rotated at any moment, and the opening of specific files is
149 inherently racy.</para>
150
151 <para><function>sd_journal_open_files_fd()</function> is similar to <function>sd_journal_open_files()</function>
152 but takes an array of open file descriptors that must reference journal files, instead of an array of file system
153 paths. Pass the array of file descriptors as second argument, and the number of array entries in the third. The
154 flags parameter must be passed as 0.</para>
798d3a52
ZJS
155
156 <para><varname>sd_journal</varname> objects cannot be used in the
157 child after a fork. Functions which take a journal object as an
158 argument (<function>sd_journal_next()</function> and others) will
159 return <constant>-ECHILD</constant> after a fork.
160 </para>
161
162 <para><function>sd_journal_close()</function> will close the
163 journal context allocated with
164 <function>sd_journal_open()</function> or
165 <function>sd_journal_open_directory()</function> and free its
166 resources.</para>
167
168 <para>When opening the journal only journal files accessible to
169 the calling user will be opened. If journal files are not
170 accessible to the caller, this will be silently ignored.</para>
171
172 <para>See
173 <citerefentry><refentrytitle>sd_journal_next</refentrytitle><manvolnum>3</manvolnum></citerefentry>
174 for an example of how to iterate through the journal after opening
175 it with <function>sd_journal_open()</function>.</para>
176
177 <para>A journal context object returned by
178 <function>sd_journal_open()</function> references a specific
179 journal entry as <emphasis>current</emphasis> entry, similar to a
180 file seek index in a classic file system file, but without
181 absolute positions. It may be altered with
182 <citerefentry><refentrytitle>sd_journal_next</refentrytitle><manvolnum>3</manvolnum></citerefentry>
183 and
184 <citerefentry><refentrytitle>sd_journal_seek_head</refentrytitle><manvolnum>3</manvolnum></citerefentry>
185 and related calls. The current entry position may be exported in
186 <emphasis>cursor</emphasis> strings, as accessible via
187 <citerefentry><refentrytitle>sd_journal_get_cursor</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
188 Cursor strings may be used to globally identify a specific journal
189 entry in a stable way and then later to seek to it (or if the
190 specific entry is not available locally, to its closest entry in
191 time)
192 <citerefentry><refentrytitle>sd_journal_seek_cursor</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para>
193
194 <para>Notification of journal changes is available via
195 <function>sd_journal_get_fd()</function> and related calls.</para>
196 </refsect1>
197
198 <refsect1>
199 <title>Return Value</title>
200
201 <para>The <function>sd_journal_open()</function>,
202 <function>sd_journal_open_directory()</function>, and
203 <function>sd_journal_open_files()</function> calls return 0 on
204 success or a negative errno-style error code.
205 <function>sd_journal_close()</function> returns nothing.</para>
206 </refsect1>
207
208 <refsect1>
209 <title>Notes</title>
210
a8d46a16
ZJS
211 <para>All functions listed here are thread-agnostic and only a single thread may operate
212 on a given <structname>sd_journal</structname> object.</para>
213
798d3a52
ZJS
214 <para>The <function>sd_journal_open()</function>,
215 <function>sd_journal_open_directory()</function> and
216 <function>sd_journal_close()</function> interfaces are available
217 as a shared library, which can be compiled and linked to with the
218 <constant>libsystemd</constant> <citerefentry project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
219 file.</para>
220 </refsect1>
221
798d3a52
ZJS
222 <refsect1>
223 <title>See Also</title>
224
225 <para>
226 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
227 <citerefentry><refentrytitle>sd-journal</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
228 <citerefentry><refentrytitle>sd_journal_next</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
229 <citerefentry><refentrytitle>sd_journal_get_data</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
230 <citerefentry><refentrytitle>systemd-machined</refentrytitle><manvolnum>8</manvolnum></citerefentry>
231 </para>
232 </refsect1>
3bb55eee
LP
233
234</refentry>