]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/journal/journald-server.h
Merge pull request #28697 from 1awesomeJ/new_bsod
[thirdparty/systemd.git] / src / journal / journald-server.h
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include <stdbool.h>
5 #include <sys/types.h>
6
7 #include "sd-event.h"
8
9 typedef struct Server Server;
10
11 #include "common-signal.h"
12 #include "conf-parser.h"
13 #include "hashmap.h"
14 #include "journald-context.h"
15 #include "journald-rate-limit.h"
16 #include "journald-stream.h"
17 #include "list.h"
18 #include "managed-journal-file.h"
19 #include "prioq.h"
20 #include "ratelimit.h"
21 #include "time-util.h"
22 #include "varlink.h"
23
24 typedef enum Storage {
25 STORAGE_AUTO,
26 STORAGE_VOLATILE,
27 STORAGE_PERSISTENT,
28 STORAGE_NONE,
29 _STORAGE_MAX,
30 _STORAGE_INVALID = -EINVAL,
31 } Storage;
32
33 typedef enum SplitMode {
34 SPLIT_UID,
35 SPLIT_LOGIN, /* deprecated */
36 SPLIT_NONE,
37 _SPLIT_MAX,
38 _SPLIT_INVALID = -EINVAL,
39 } SplitMode;
40
41 typedef struct JournalCompressOptions {
42 bool enabled;
43 uint64_t threshold_bytes;
44 } JournalCompressOptions;
45
46 typedef struct JournalStorageSpace {
47 usec_t timestamp;
48
49 uint64_t available;
50 uint64_t limit;
51
52 uint64_t vfs_used; /* space used by journal files */
53 uint64_t vfs_available;
54 } JournalStorageSpace;
55
56 typedef struct JournalStorage {
57 const char *name;
58 char *path;
59
60 JournalMetrics metrics;
61 JournalStorageSpace space;
62 } JournalStorage;
63
64 /* This structure will be kept in $RUNTIME_DIRECTORY/seqnum and is mapped by journald, and is used to
65 * maintain the sequence number counter with its seqnum ID */
66 typedef struct SeqnumData {
67 sd_id128_t id;
68 uint64_t seqnum;
69 } SeqnumData;
70
71 struct Server {
72 char *namespace;
73
74 int syslog_fd;
75 int native_fd;
76 int stdout_fd;
77 int dev_kmsg_fd;
78 int audit_fd;
79 int hostname_fd;
80 int notify_fd;
81
82 sd_event *event;
83
84 sd_event_source *syslog_event_source;
85 sd_event_source *native_event_source;
86 sd_event_source *stdout_event_source;
87 sd_event_source *dev_kmsg_event_source;
88 sd_event_source *audit_event_source;
89 sd_event_source *sync_event_source;
90 sd_event_source *sigusr1_event_source;
91 sd_event_source *sigusr2_event_source;
92 sd_event_source *sigterm_event_source;
93 sd_event_source *sigint_event_source;
94 sd_event_source *sigrtmin1_event_source;
95 sd_event_source *hostname_event_source;
96 sd_event_source *notify_event_source;
97 sd_event_source *watchdog_event_source;
98 sd_event_source *idle_event_source;
99 struct sigrtmin18_info sigrtmin18_info;
100
101 ManagedJournalFile *runtime_journal;
102 ManagedJournalFile *system_journal;
103 OrderedHashmap *user_journals;
104
105 SeqnumData *seqnum;
106
107 char *buffer;
108
109 JournalRateLimit *ratelimit;
110 usec_t sync_interval_usec;
111 usec_t ratelimit_interval;
112 unsigned ratelimit_burst;
113
114 JournalStorage runtime_storage;
115 JournalStorage system_storage;
116
117 JournalCompressOptions compress;
118 bool seal;
119 bool read_kmsg;
120 int set_audit;
121
122 bool forward_to_kmsg;
123 bool forward_to_syslog;
124 bool forward_to_console;
125 bool forward_to_wall;
126
127 unsigned n_forward_syslog_missed;
128 usec_t last_warn_forward_syslog_missed;
129
130 usec_t max_retention_usec;
131 usec_t max_file_usec;
132 usec_t oldest_file_usec;
133
134 LIST_HEAD(StdoutStream, stdout_streams);
135 LIST_HEAD(StdoutStream, stdout_streams_notify_queue);
136 unsigned n_stdout_streams;
137
138 char *tty_path;
139
140 int max_level_store;
141 int max_level_syslog;
142 int max_level_kmsg;
143 int max_level_console;
144 int max_level_wall;
145
146 Storage storage;
147 SplitMode split_mode;
148
149 MMapCache *mmap;
150
151 Set *deferred_closes;
152
153 uint64_t *kernel_seqnum;
154 bool dev_kmsg_readable:1;
155 RateLimit kmsg_own_ratelimit;
156
157 bool send_watchdog:1;
158 bool sent_notify_ready:1;
159 bool sync_scheduled:1;
160
161 char machine_id_field[sizeof("_MACHINE_ID=") + 32];
162 char boot_id_field[sizeof("_BOOT_ID=") + 32];
163 char *hostname_field;
164 char *namespace_field;
165 char *runtime_directory;
166
167 /* Cached cgroup root, so that we don't have to query that all the time */
168 char *cgroup_root;
169
170 usec_t watchdog_usec;
171
172 usec_t last_realtime_clock;
173
174 size_t line_max;
175
176 /* Caching of client metadata */
177 Hashmap *client_contexts;
178 Prioq *client_contexts_lru;
179
180 usec_t last_cache_pid_flush;
181
182 ClientContext *my_context; /* the context of journald itself */
183 ClientContext *pid1_context; /* the context of PID 1 */
184
185 VarlinkServer *varlink_server;
186 };
187
188 #define SERVER_MACHINE_ID(s) ((s)->machine_id_field + STRLEN("_MACHINE_ID="))
189
190 /* Extra fields for any log messages */
191 #define N_IOVEC_META_FIELDS 24
192
193 /* Extra fields for log messages that contain OBJECT_PID= (i.e. log about another process) */
194 #define N_IOVEC_OBJECT_FIELDS 18
195
196 /* Maximum number of fields we'll add in for driver (i.e. internal) messages */
197 #define N_IOVEC_PAYLOAD_FIELDS 16
198
199 /* kmsg: Maximum number of extra fields we'll import from the kernel's /dev/kmsg */
200 #define N_IOVEC_KERNEL_FIELDS 64
201
202 /* kmsg: Maximum number of extra fields we'll import from udev's devices */
203 #define N_IOVEC_UDEV_FIELDS 32
204
205 /* audit: Maximum number of extra fields we'll import from audit messages */
206 #define N_IOVEC_AUDIT_FIELDS 64
207
208 void server_dispatch_message(Server *s, struct iovec *iovec, size_t n, size_t m, ClientContext *c, const struct timeval *tv, int priority, pid_t object_pid);
209 void server_driver_message(Server *s, pid_t object_pid, const char *message_id, const char *format, ...) _sentinel_ _printf_(4,0);
210
211 /* gperf lookup function */
212 const struct ConfigPerfItem* journald_gperf_lookup(const char *key, GPERF_LEN_TYPE length);
213
214 CONFIG_PARSER_PROTOTYPE(config_parse_storage);
215 CONFIG_PARSER_PROTOTYPE(config_parse_line_max);
216 CONFIG_PARSER_PROTOTYPE(config_parse_compress);
217
218 const char *storage_to_string(Storage s) _const_;
219 Storage storage_from_string(const char *s) _pure_;
220
221 CONFIG_PARSER_PROTOTYPE(config_parse_split_mode);
222
223 const char *split_mode_to_string(SplitMode s) _const_;
224 SplitMode split_mode_from_string(const char *s) _pure_;
225
226 int server_init(Server *s, const char *namespace);
227 void server_done(Server *s);
228 void server_sync(Server *s);
229 void server_vacuum(Server *s, bool verbose);
230 void server_rotate(Server *s);
231 int server_schedule_sync(Server *s, int priority);
232 int server_flush_to_var(Server *s, bool require_flag_file);
233 void server_maybe_append_tags(Server *s);
234 int server_process_datagram(sd_event_source *es, int fd, uint32_t revents, void *userdata);
235 void server_space_usage_message(Server *s, JournalStorage *storage);
236
237 int server_start_or_stop_idle_timer(Server *s);
238 int server_refresh_idle_timer(Server *s);
239
240 int server_map_seqnum_file(Server *s, const char *fname, size_t size, void **ret);
241 void server_unmap_seqnum_file(void *p, size_t size);