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