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">
6 This file is part of systemd.
8 Copyright 2012 Lennart Poettering
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.
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.
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/>.
24 <refentry id="sd_journal_open">
27 <title>sd_journal_open</title>
28 <productname>systemd</productname>
32 <contrib>Developer</contrib>
33 <firstname>Lennart</firstname>
34 <surname>Poettering</surname>
35 <email>lennart@poettering.net</email>
41 <refentrytitle>sd_journal_open</refentrytitle>
42 <manvolnum>3</manvolnum>
46 <refname>sd_journal_open</refname>
47 <refname>sd_journal_open_directory</refname>
48 <refname>sd_journal_open_files</refname>
49 <refname>sd_journal_close</refname>
50 <refname>sd_journal</refname>
51 <refname>SD_JOURNAL_LOCAL_ONLY</refname>
52 <refname>SD_JOURNAL_RUNTIME_ONLY</refname>
53 <refname>SD_JOURNAL_SYSTEM</refname>
54 <refname>SD_JOURNAL_CURRENT_USER</refname>
55 <refpurpose>Open the system journal for reading</refpurpose>
60 <funcsynopsisinfo>#include <systemd/sd-journal.h></funcsynopsisinfo>
63 <funcdef>int <function>sd_journal_open</function></funcdef>
64 <paramdef>sd_journal** <parameter>ret</parameter></paramdef>
65 <paramdef>int <parameter>flags</parameter></paramdef>
69 <funcdef>int <function>sd_journal_open_directory</function></funcdef>
70 <paramdef>sd_journal** <parameter>ret</parameter></paramdef>
71 <paramdef>const char* <parameter>path</parameter></paramdef>
72 <paramdef>int <parameter>flags</parameter></paramdef>
76 <funcdef>int <function>sd_journal_open_files</function></funcdef>
77 <paramdef>sd_journal** <parameter>ret</parameter></paramdef>
78 <paramdef>const char** <parameter>paths</parameter></paramdef>
79 <paramdef>int <parameter>flags</parameter></paramdef>
83 <funcdef>void <function>sd_journal_close</function></funcdef>
84 <paramdef>sd_journal* <parameter>j</parameter></paramdef>
90 <title>Description</title>
92 <para><function>sd_journal_open()</function> opens
93 the log journal for reading. It will find all journal
94 files automatically and interleave them automatically
95 when reading. As first argument it takes a pointer to
96 a <literal>sd_journal</literal> pointer, which on
97 success will contain journal context object afterwards. The
98 second argument is a flags field, which may consist of
99 the following flags ORed together:
100 <literal>SD_JOURNAL_LOCAL_ONLY</literal> makes sure
101 only journal files generated on the local machine will
102 be opened. <literal>SD_JOURNAL_RUNTIME_ONLY</literal>
103 makes sure only volatile journal files will be opened,
104 excluding those which are stored on persistent
105 storage. <literal>SD_JOURNAL_SYSTEM</literal>
106 will cause journal files of system services and the
107 kernel (in opposition to user session processes) to
108 be opened. <literal>SD_JOURNAL_CURRENT_USER</literal>
109 will cause journal files of the current user to be
110 opened. If neither <literal>SD_JOURNAL_SYSTEM</literal>
111 nor <literal>SD_JOURNAL_CURRENT_USER</literal> are
112 specified, all journal file types will be opened.</para>
114 <para><function>sd_journal_open_directory()</function>
115 is similar to <function>sd_journal_open()</function>
116 but takes an absolute directory path as argument. All
117 journal files in this directory will be opened and
118 interleaved automatically. This call also takes a
119 flags argument, but it must be passed as 0 as no flags
120 are currently understood for this call.</para>
122 <para><function>sd_journal_open_files()</function>
123 is similar to <function>sd_journal_open()</function>
124 but takes a <literal>NULL</literal>-terminated list
125 of file paths to open. All files will be opened and
126 interleaved automatically. This call also takes a
127 flags argument, but it must be passed as 0 as no flags
128 are currently understood for this call.</para>
130 <para><function>sd_journal_close()</function> will
131 close the journal context allocated with
132 <function>sd_journal_open()</function> or
133 <function>sd_journal_open_directory()</function> and
134 free its resources.</para>
136 <para>When opening the journal only journal files
137 accessible to the calling user will be opened. If
138 journal files are not accessible to the caller this
139 will be silently ignored.</para>
142 <citerefentry><refentrytitle>sd_journal_next</refentrytitle><manvolnum>3</manvolnum></citerefentry>
143 for an example how to iterate through the journal
144 after opening it with
145 <function>sd_journal_open()</function>.</para>
147 <para>A journal context object returned by
148 <function>sd_journal_open()</function> references a
149 specific journal entry as <emphasis>current</emphasis> entry,
150 similar to a file seek index in a classic file system
151 file, but without absolute positions. It may be
153 <citerefentry><refentrytitle>sd_journal_next</refentrytitle><manvolnum>3</manvolnum></citerefentry>
155 <citerefentry><refentrytitle>sd_journal_seek_head</refentrytitle><manvolnum>3</manvolnum></citerefentry>
156 and related calls. The current entry position may be
157 exported in <emphasis>cursor</emphasis> strings, as accessible
159 <citerefentry><refentrytitle>sd_journal_get_cursor</refentrytitle><manvolnum>3</manvolnum></citerefentry>. Cursor
160 strings may be used to globally identify a specific
161 journal entry in a stable way and then later to seek
162 to it (or if the specific entry is not available
163 locally, to its closest entry in time)
164 <citerefentry><refentrytitle>sd_journal_seek_cursor</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para>
166 <para>Notification of journal changes is available via
167 <function>sd_journal_get_fd()</function> and related
172 <title>Return Value</title>
174 <para>The <function>sd_journal_open()</function> and
175 <function>sd_journal_open_directory()</function> calls
176 return 0 on success or a negative errno-style error
177 code. <function>sd_journal_close()</function> returns
184 <para>The <function>sd_journal_open()</function>,
185 <function>sd_journal_open_directory()</function> and
186 <function>sd_journal_close()</function> interfaces are
187 available as shared library, which can be compiled and
189 <literal>libsystemd-journal</literal>
190 <citerefentry><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
195 <title>History</title>
197 <para><function>sd_journal_open()</function>,
198 <function>sd_journal_close()</function>,
199 <literal>SD_JOURNAL_LOCAL_ONLY</literal>,
200 <literal>SD_JOURNAL_RUNTIME_ONLY</literal>,
201 <literal>SD_JOURNAL_SYSTEM_ONLY</literal> were added
202 in systemd-38.</para>
204 <para><function>sd_journal_open_directory()</function>
205 was added in systemd-187.</para>
207 <para><literal>SD_JOURNAL_SYSTEM</literal>,
208 <literal>SD_JOURNAL_CURRENT_USER</literal>,
209 and <function>sd_journal_open_files()</function>
210 were added in systemd-205.
211 <literal>SD_JOURNAL_SYSTEM_ONLY</literal>
212 was deprecated.</para>
216 <title>See Also</title>
219 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
220 <citerefentry><refentrytitle>sd-journal</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
221 <citerefentry><refentrytitle>sd_journal_next</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
222 <citerefentry><refentrytitle>sd_journal_get_data</refentrytitle><manvolnum>3</manvolnum></citerefentry>