1SD_JOURNAL_OPEN(3) sd_journal_open SD_JOURNAL_OPEN(3)
2
3
4
6 sd_journal_open, sd_journal_open_directory,
7 sd_journal_open_directory_fd, sd_journal_open_files,
8 sd_journal_open_files_fd, sd_journal_close, sd_journal,
9 SD_JOURNAL_LOCAL_ONLY, SD_JOURNAL_RUNTIME_ONLY, SD_JOURNAL_SYSTEM,
10 SD_JOURNAL_CURRENT_USER, SD_JOURNAL_OS_ROOT - Open the system journal
11 for reading
12
14 #include <systemd/sd-journal.h>
15
16 int sd_journal_open(sd_journal **ret, int flags);
17
18 int sd_journal_open_directory(sd_journal **ret, const char *path,
19 int flags);
20
21 int sd_journal_open_directory_fd(sd_journal **ret, int fd, int flags);
22
23 int sd_journal_open_files(sd_journal **ret, const char **paths,
24 int flags);
25
26 int sd_journal_open_files_fd(sd_journal **ret, int fds[],
27 unsigned n_fds, int flags);
28
29 void sd_journal_close(sd_journal *j);
30
32 sd_journal_open() opens the log journal for reading. It will find all
33 journal files automatically and interleave them automatically when
34 reading. As first argument it takes a pointer to a sd_journal pointer,
35 which, on success, will contain a journal context object. The second
36 argument is a flags field, which may consist of the following flags
37 ORed together: SD_JOURNAL_LOCAL_ONLY makes sure only journal files
38 generated on the local machine will be opened. SD_JOURNAL_RUNTIME_ONLY
39 makes sure only volatile journal files will be opened, excluding those
40 which are stored on persistent storage. SD_JOURNAL_SYSTEM will cause
41 journal files of system services and the kernel (in opposition to user
42 session processes) to be opened. SD_JOURNAL_CURRENT_USER will cause
43 journal files of the current user to be opened. If neither
44 SD_JOURNAL_SYSTEM nor SD_JOURNAL_CURRENT_USER are specified, all
45 journal file types will be opened.
46
47 sd_journal_open_directory() is similar to sd_journal_open() but takes
48 an absolute directory path as argument. All journal files in this
49 directory will be opened and interleaved automatically. This call also
50 takes a flags argument. The flags parameters accepted by this call are
51 SD_JOURNAL_OS_ROOT, SD_JOURNAL_SYSTEM, and SD_JOURNAL_CURRENT_USER. If
52 SD_JOURNAL_OS_ROOT is specified, journal files are searched for below
53 the usual /var/log/journal and /run/log/journal relative to the
54 specified path, instead of directly beneath it. The other two flags
55 limit which files are opened, the same as for sd_journal_open().
56
57 sd_journal_open_directory_fd() is similar to
58 sd_journal_open_directory(), but takes a file descriptor referencing a
59 directory in the file system instead of an absolute file system path.
60
61 sd_journal_open_files() is similar to sd_journal_open() but takes a
62 NULL-terminated list of file paths to open. All files will be opened
63 and interleaved automatically. This call also takes a flags argument,
64 but it must be passed as 0 as no flags are currently understood for
65 this call. Please note that in the case of a live journal, this
66 function is only useful for debugging, because individual journal files
67 can be rotated at any moment, and the opening of specific files is
68 inherently racy.
69
70 sd_journal_open_files_fd() is similar to sd_journal_open_files() but
71 takes an array of open file descriptors that must reference journal
72 files, instead of an array of file system paths. Pass the array of file
73 descriptors as second argument, and the number of array entries in the
74 third. The flags parameter must be passed as 0.
75
76 sd_journal objects cannot be used in the child after a fork. Functions
77 which take a journal object as an argument (sd_journal_next() and
78 others) will return -ECHILD after a fork.
79
80 sd_journal_close() will close the journal context allocated with
81 sd_journal_open() or sd_journal_open_directory() and free its
82 resources.
83
84 When opening the journal only journal files accessible to the calling
85 user will be opened. If journal files are not accessible to the caller,
86 this will be silently ignored.
87
88 See sd_journal_next(3) for an example of how to iterate through the
89 journal after opening it with sd_journal_open().
90
91 A journal context object returned by sd_journal_open() references a
92 specific journal entry as current entry, similar to a file seek index
93 in a classic file system file, but without absolute positions. It may
94 be altered with sd_journal_next(3) and sd_journal_seek_head(3) and
95 related calls. The current entry position may be exported in cursor
96 strings, as accessible via sd_journal_get_cursor(3). Cursor strings may
97 be used to globally identify a specific journal entry in a stable way
98 and then later to seek to it (or if the specific entry is not available
99 locally, to its closest entry in time) sd_journal_seek_cursor(3).
100
101 Notification of journal changes is available via sd_journal_get_fd()
102 and related calls.
103
105 The sd_journal_open(), sd_journal_open_directory(), and
106 sd_journal_open_files() calls return 0 on success or a negative
107 errno-style error code. sd_journal_close() returns nothing.
108
110 All functions listed here are thread-agnostic and only a single
111 specific thread may operate on a given object during its entire
112 lifetime. It's safe to allocate multiple independent objects and use
113 each from a specific thread in parallel. However, it's not safe to
114 allocate such an object in one thread, and operate or free it from any
115 other, even if locking is used to ensure these threads don't operate on
116 it at the very same time.
117
118 These APIs are implemented as a shared library, which can be compiled
119 and linked to with the libsystemd pkg-config(1) file.
120
122 systemd(1), sd-journal(3), systemd-journald.service(8),
123 sd_journal_next(3), sd_journal_get_data(3)
124
125
126
127systemd 243 SD_JOURNAL_OPEN(3)