man-pages/man3/sd_journal_open.3.html
2021-03-31 01:06:50 +01:00

239 lines
9.0 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of SD_JOURNAL_OPEN</TITLE>
</HEAD><BODY>
<H1>SD_JOURNAL_OPEN</H1>
Section: sd_journal_open (3)<BR>Updated: <BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
sd_journal_open, sd_journal_open_directory, sd_journal_open_directory_fd, sd_journal_open_files, sd_journal_open_files_fd, sd_journal_close, sd_journal, SD_JOURNAL_LOCAL_ONLY, SD_JOURNAL_RUNTIME_ONLY, SD_JOURNAL_SYSTEM, SD_JOURNAL_CURRENT_USER, SD_JOURNAL_OS_ROOT, SD_JOURNAL_ALL_NAMESPACES, SD_JOURNAL_INCLUDE_DEFAULT_NAMESPACE - Open the system journal for reading
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<P>
<B>
</B><PRE>
#include &lt;<A HREF="file:///usr/include/systemd/sd-journal.h">systemd/sd-journal.h</A>&gt;
</PRE>
<DL COMPACT>
<DT id="1">
<B>int sd_journal_open(sd_journal&nbsp;**</B><I>ret</I><B>, int&nbsp;</B><I>flags</I><B>);</B>
<DT id="2">
<B>int sd_journal_open_namespace(sd_journal&nbsp;**</B><I>ret</I><B>, const&nbsp;char&nbsp;*</B><I>namespace</I><B>, int&nbsp;</B><I>flags</I><B>);</B>
<DT id="3">
<B>int sd_journal_open_directory(sd_journal&nbsp;**</B><I>ret</I><B>, const&nbsp;char&nbsp;*</B><I>path</I><B>, int&nbsp;</B><I>flags</I><B>);</B>
<DT id="4">
<B>int sd_journal_open_directory_fd(sd_journal&nbsp;**</B><I>ret</I><B>, int&nbsp;</B><I>fd</I><B>, int&nbsp;</B><I>flags</I><B>);</B>
<DT id="5">
<B>int sd_journal_open_files(sd_journal&nbsp;**</B><I>ret</I><B>, const&nbsp;char&nbsp;**</B><I>paths</I><B>, int&nbsp;</B><I>flags</I><B>);</B>
<DT id="6">
<B>int sd_journal_open_files_fd(sd_journal&nbsp;**</B><I>ret</I><B>, int&nbsp;</B><I>fds[]</I><B>, unsigned&nbsp;</B><I>n_fds</I><B>, int&nbsp;</B><I>flags</I><B>);</B>
<DT id="7">
<B>void sd_journal_close(sd_journal&nbsp;*</B><I>j</I><B>);</B>
</DL>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
<P>
<B>sd_journal_open()</B>
<DD>opens the log journal for reading. It will find all journal files automatically and interleave them automatically when reading. As first argument it takes a pointer to a
<I>sd_journal</I>
pointer, which, on success, will contain a journal context object. The second argument is a flags field, which may consist of the following flags ORed together:
<B>SD_JOURNAL_LOCAL_ONLY</B>
makes sure only journal files generated on the local machine will be opened.
<B>SD_JOURNAL_RUNTIME_ONLY</B>
makes sure only volatile journal files will be opened, excluding those which are stored on persistent storage.
<B>SD_JOURNAL_SYSTEM</B>
will cause journal files of system services and the kernel (in opposition to user session processes) to be opened.
<B>SD_JOURNAL_CURRENT_USER</B>
will cause journal files of the current user to be opened. If neither
<B>SD_JOURNAL_SYSTEM</B>
nor
<B>SD_JOURNAL_CURRENT_USER</B>
are specified, all journal file types will be opened.
<P>
<B>sd_journal_open_namespace()</B>
is similar to
<B>sd_journal_open()</B>
but takes an additional
<I>namespace</I>
parameter that specifies which journal namespace to operate on. If specified as
<B>NULL</B>
the call is identical to
<B>sd_journal_open()</B>. If non-<B>NULL</B>
only data from the namespace identified by the specified parameter is accessed. This call understands two additional flags: if
<B>SD_JOURNAL_ALL_NAMESPACES</B>
is specified the
<I>namespace</I>
parameter is ignored and all defined namespaces are accessed simultaneously; if
<B>SD_JOURNAL_INCLUDE_DEFAULT_NAMESPACE</B>
the specified namespace and the default namespace are accessed but no others (this flag has no effect when
<I>namespace</I>
is passed as
<B>NULL</B>). For details about journal namespaces see
<B><A HREF="/cgi-bin/man/man2html?8+systemd-journald.service">systemd-journald.service</A></B>(8).
<P>
<B>sd_journal_open_directory()</B>
is similar to
<B>sd_journal_open()</B>
but takes an absolute directory path as argument. All journal files in this directory will be opened and interleaved automatically. This call also takes a flags argument. The flags parameters accepted by this call are
<B>SD_JOURNAL_OS_ROOT</B>,
<B>SD_JOURNAL_SYSTEM</B>, and
<B>SD_JOURNAL_CURRENT_USER</B>. If
<B>SD_JOURNAL_OS_ROOT</B>
is specified, journal files are searched for below the usual
/var/log/journal
and
/run/log/journal
relative to the specified path, instead of directly beneath it. The other two flags limit which files are opened, the same as for
<B>sd_journal_open()</B>.
<P>
<B>sd_journal_open_directory_fd()</B>
is similar to
<B>sd_journal_open_directory()</B>, but takes a file descriptor referencing a directory in the file system instead of an absolute file system path.
<P>
<B>sd_journal_open_files()</B>
is similar to
<B>sd_journal_open()</B>
but takes a
<B>NULL</B>-terminated list of file paths to open. All files will be opened and interleaved automatically. This call also takes a flags argument, but it must be passed as 0 as no flags are currently understood for this call. Please note that in the case of a live journal, this function is only useful for debugging, because individual journal files can be rotated at any moment, and the opening of specific files is inherently racy.
<P>
<B>sd_journal_open_files_fd()</B>
is similar to
<B>sd_journal_open_files()</B>
but takes an array of open file descriptors that must reference journal files, instead of an array of file system paths. Pass the array of file descriptors as second argument, and the number of array entries in the third. The flags parameter must be passed as 0.
<P>
<I>sd_journal</I>
objects cannot be used in the child after a fork. Functions which take a journal object as an argument (<B>sd_journal_next()</B>
and others) will return
<B>-ECHILD</B>
after a fork.
<P>
<B>sd_journal_close()</B>
will close the journal context allocated with
<B>sd_journal_open()</B>
or
<B>sd_journal_open_directory()</B>
and free its resources.
<P>
When opening the journal only journal files accessible to the calling user will be opened. If journal files are not accessible to the caller, this will be silently ignored.
<P>
See
<B><A HREF="/cgi-bin/man/man2html?3+sd_journal_next">sd_journal_next</A></B>(3)
for an example of how to iterate through the journal after opening it with
<B>sd_journal_open()</B>.
<P>
A journal context object returned by
<B>sd_journal_open()</B>
references a specific journal entry as
<I>current</I>
entry, similar to a file seek index in a classic file system file, but without absolute positions. It may be altered with
<B><A HREF="/cgi-bin/man/man2html?3+sd_journal_next">sd_journal_next</A></B>(3)
and
<B><A HREF="/cgi-bin/man/man2html?3+sd_journal_seek_head">sd_journal_seek_head</A></B>(3)
and related calls. The current entry position may be exported in
<I>cursor</I>
strings, as accessible via
<B><A HREF="/cgi-bin/man/man2html?3+sd_journal_get_cursor">sd_journal_get_cursor</A></B>(3). Cursor strings may be used to globally identify a specific journal entry in a stable way and then later to seek to it (or if the specific entry is not available locally, to its closest entry in time)
<B><A HREF="/cgi-bin/man/man2html?3+sd_journal_seek_cursor">sd_journal_seek_cursor</A></B>(3).
<P>
Notification of journal changes is available via
<B>sd_journal_get_fd()</B>
and related calls.
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
<P>
The
<B>sd_journal_open()</B>,
<B>sd_journal_open_directory()</B>, and
<B>sd_journal_open_files()</B>
calls return 0 on success or a negative errno-style error code.
<B>sd_journal_close()</B>
returns nothing.
<A NAME="lbAF">&nbsp;</A>
<H2>NOTES</H2>
<P>
All functions listed here are thread-agnostic and only a single specific thread may operate on a given object during its entire lifetime. It's safe to allocate multiple independent objects and use each from a specific thread in parallel. However, it's not safe to allocate such an object in one thread, and operate or free it from any other, even if locking is used to ensure these threads don't operate on it at the very same time.
<P>
These APIs are implemented as a shared library, which can be compiled and linked to with the
<B>libsystemd</B>&nbsp;<B><A HREF="/cgi-bin/man/man2html?1+pkg-config">pkg-config</A></B>(1)
file.
<A NAME="lbAG">&nbsp;</A>
<H2>SEE ALSO</H2>
<P>
<B><A HREF="/cgi-bin/man/man2html?1+systemd">systemd</A></B>(1),
<B><A HREF="/cgi-bin/man/man2html?3+sd-journal">sd-journal</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?8+systemd-journald.service">systemd-journald.service</A></B>(8),
<B><A HREF="/cgi-bin/man/man2html?3+sd_journal_next">sd_journal_next</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+sd_journal_get_data">sd_journal_get_data</A></B>(3)
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="8"><A HREF="#lbAB">NAME</A><DD>
<DT id="9"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="10"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="11"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT id="12"><A HREF="#lbAF">NOTES</A><DD>
<DT id="13"><A HREF="#lbAG">SEE ALSO</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:55 GMT, March 31, 2021
</BODY>
</HTML>