]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/sd_journal_open.xml
core: use the correct APIs to determine whether a dual timestamp is initialized
[thirdparty/systemd.git] / man / sd_journal_open.xml
1 <?xml version='1.0'?> <!--*-nxml-*-->
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
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
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>
48 <refname>sd_journal_open_directory_fd</refname>
49 <refname>sd_journal_open_files</refname>
50 <refname>sd_journal_open_files_fd</refname>
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>
57 <refname>SD_JOURNAL_OS_ROOT</refname>
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
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
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>
93 <funcdef>int <function>sd_journal_open_files_fd</function></funcdef>
94 <paramdef>sd_journal **<parameter>ret</parameter></paramdef>
95 <paramdef>int <parameter>fds[]</parameter></paramdef>
96 <paramdef>unsigned <parameter>n_fds</parameter></paramdef>
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
113 takes a pointer to a <varname>sd_journal</varname> pointer, which,
114 on success, will contain a journal context object. The second
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
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
132 automatically. This call also takes a flags argument. The only flags parameter accepted by this call is
133 <constant>SD_JOURNAL_OS_ROOT</constant>. If specified, the journal files are searched below the usual
134 <filename>/var/log/journal</filename> and <filename>/run/log/journal</filename> relative to the specified path,
135 instead of directly beneath it.</para>
136
137 <para><function>sd_journal_open_directory_fd()</function> is similar to
138 <function>sd_journal_open_directory()</function>, but takes a file descriptor referencing a directory in the file
139 system instead of an absolute file system path.</para>
140
141 <para><function>sd_journal_open_files()</function> is similar to <function>sd_journal_open()</function> but takes a
142 <constant>NULL</constant>-terminated list of file paths to open. All files will be opened and interleaved
143 automatically. This call also takes a flags argument, but it must be passed as 0 as no flags are currently
144 understood for this call. Please note that in the case of a live journal, this function is only useful for
145 debugging, because individual journal files can be rotated at any moment, and the opening of specific files is
146 inherently racy.</para>
147
148 <para><function>sd_journal_open_files_fd()</function> is similar to <function>sd_journal_open_files()</function>
149 but takes an array of open file descriptors that must reference journal files, instead of an array of file system
150 paths. Pass the array of file descriptors as second argument, and the number of array entries in the third. The
151 flags parameter must be passed as 0.</para>
152
153 <para><varname>sd_journal</varname> objects cannot be used in the
154 child after a fork. Functions which take a journal object as an
155 argument (<function>sd_journal_next()</function> and others) will
156 return <constant>-ECHILD</constant> after a fork.
157 </para>
158
159 <para><function>sd_journal_close()</function> will close the
160 journal context allocated with
161 <function>sd_journal_open()</function> or
162 <function>sd_journal_open_directory()</function> and free its
163 resources.</para>
164
165 <para>When opening the journal only journal files accessible to
166 the calling user will be opened. If journal files are not
167 accessible to the caller, this will be silently ignored.</para>
168
169 <para>See
170 <citerefentry><refentrytitle>sd_journal_next</refentrytitle><manvolnum>3</manvolnum></citerefentry>
171 for an example of how to iterate through the journal after opening
172 it with <function>sd_journal_open()</function>.</para>
173
174 <para>A journal context object returned by
175 <function>sd_journal_open()</function> references a specific
176 journal entry as <emphasis>current</emphasis> entry, similar to a
177 file seek index in a classic file system file, but without
178 absolute positions. It may be altered with
179 <citerefentry><refentrytitle>sd_journal_next</refentrytitle><manvolnum>3</manvolnum></citerefentry>
180 and
181 <citerefentry><refentrytitle>sd_journal_seek_head</refentrytitle><manvolnum>3</manvolnum></citerefentry>
182 and related calls. The current entry position may be exported in
183 <emphasis>cursor</emphasis> strings, as accessible via
184 <citerefentry><refentrytitle>sd_journal_get_cursor</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
185 Cursor strings may be used to globally identify a specific journal
186 entry in a stable way and then later to seek to it (or if the
187 specific entry is not available locally, to its closest entry in
188 time)
189 <citerefentry><refentrytitle>sd_journal_seek_cursor</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para>
190
191 <para>Notification of journal changes is available via
192 <function>sd_journal_get_fd()</function> and related calls.</para>
193 </refsect1>
194
195 <refsect1>
196 <title>Return Value</title>
197
198 <para>The <function>sd_journal_open()</function>,
199 <function>sd_journal_open_directory()</function>, and
200 <function>sd_journal_open_files()</function> calls return 0 on
201 success or a negative errno-style error code.
202 <function>sd_journal_close()</function> returns nothing.</para>
203 </refsect1>
204
205 <refsect1>
206 <title>Notes</title>
207
208 <para>The <function>sd_journal_open()</function>,
209 <function>sd_journal_open_directory()</function> and
210 <function>sd_journal_close()</function> interfaces are available
211 as a shared library, which can be compiled and linked to with the
212 <constant>libsystemd</constant> <citerefentry project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
213 file.</para>
214 </refsect1>
215
216 <refsect1>
217 <title>See Also</title>
218
219 <para>
220 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
221 <citerefentry><refentrytitle>sd-journal</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
222 <citerefentry><refentrytitle>sd_journal_next</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
223 <citerefentry><refentrytitle>sd_journal_get_data</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
224 <citerefentry><refentrytitle>systemd-machined</refentrytitle><manvolnum>8</manvolnum></citerefentry>
225 </para>
226 </refsect1>
227
228 </refentry>