]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/journal/journald-server.h
tree-wide: use -EINVAL for enum invalid values
[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 "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 = -EINVAL,
29 } Storage;
30
31 typedef enum SplitMode {
32 SPLIT_UID,
33 SPLIT_LOGIN, /* deprecated */
34 SPLIT_NONE,
35 _SPLIT_MAX,
36 _SPLIT_INVALID = -EINVAL,
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 int set_audit;
112
113 bool forward_to_kmsg;
114 bool forward_to_syslog;
115 bool forward_to_console;
116 bool forward_to_wall;
117
118 unsigned n_forward_syslog_missed;
119 usec_t last_warn_forward_syslog_missed;
120
121 usec_t max_retention_usec;
122 usec_t max_file_usec;
123 usec_t oldest_file_usec;
124
125 LIST_HEAD(StdoutStream, stdout_streams);
126 LIST_HEAD(StdoutStream, stdout_streams_notify_queue);
127 unsigned n_stdout_streams;
128
129 char *tty_path;
130
131 int max_level_store;
132 int max_level_syslog;
133 int max_level_kmsg;
134 int max_level_console;
135 int max_level_wall;
136
137 Storage storage;
138 SplitMode split_mode;
139
140 MMapCache *mmap;
141
142 Set *deferred_closes;
143
144 uint64_t *kernel_seqnum;
145 bool dev_kmsg_readable:1;
146
147 bool send_watchdog:1;
148 bool sent_notify_ready:1;
149 bool sync_scheduled:1;
150
151 char machine_id_field[sizeof("_MACHINE_ID=") + 32];
152 char boot_id_field[sizeof("_BOOT_ID=") + 32];
153 char *hostname_field;
154 char *namespace_field;
155 char *runtime_directory;
156
157 /* Cached cgroup root, so that we don't have to query that all the time */
158 char *cgroup_root;
159
160 usec_t watchdog_usec;
161
162 usec_t last_realtime_clock;
163
164 size_t line_max;
165
166 /* Caching of client metadata */
167 Hashmap *client_contexts;
168 Prioq *client_contexts_lru;
169
170 usec_t last_cache_pid_flush;
171
172 ClientContext *my_context; /* the context of journald itself */
173 ClientContext *pid1_context; /* the context of PID 1 */
174
175 VarlinkServer *varlink_server;
176 };
177
178 #define SERVER_MACHINE_ID(s) ((s)->machine_id_field + STRLEN("_MACHINE_ID="))
179
180 /* Extra fields for any log messages */
181 #define N_IOVEC_META_FIELDS 23
182
183 /* Extra fields for log messages that contain OBJECT_PID= (i.e. log about another process) */
184 #define N_IOVEC_OBJECT_FIELDS 18
185
186 /* Maximum number of fields we'll add in for driver (i.e. internal) messages */
187 #define N_IOVEC_PAYLOAD_FIELDS 16
188
189 /* kmsg: Maximum number of extra fields we'll import from the kernel's /dev/kmsg */
190 #define N_IOVEC_KERNEL_FIELDS 64
191
192 /* kmsg: Maximum number of extra fields we'll import from udev's devices */
193 #define N_IOVEC_UDEV_FIELDS 32
194
195 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);
196 void server_driver_message(Server *s, pid_t object_pid, const char *message_id, const char *format, ...) _sentinel_ _printf_(4,0);
197
198 /* gperf lookup function */
199 const struct ConfigPerfItem* journald_gperf_lookup(const char *key, GPERF_LEN_TYPE length);
200
201 CONFIG_PARSER_PROTOTYPE(config_parse_storage);
202 CONFIG_PARSER_PROTOTYPE(config_parse_line_max);
203 CONFIG_PARSER_PROTOTYPE(config_parse_compress);
204
205 const char *storage_to_string(Storage s) _const_;
206 Storage storage_from_string(const char *s) _pure_;
207
208 CONFIG_PARSER_PROTOTYPE(config_parse_split_mode);
209
210 const char *split_mode_to_string(SplitMode s) _const_;
211 SplitMode split_mode_from_string(const char *s) _pure_;
212
213 int server_init(Server *s, const char *namespace);
214 void server_done(Server *s);
215 void server_sync(Server *s);
216 int server_vacuum(Server *s, bool verbose);
217 void server_rotate(Server *s);
218 int server_schedule_sync(Server *s, int priority);
219 int server_flush_to_var(Server *s, bool require_flag_file);
220 void server_maybe_append_tags(Server *s);
221 int server_process_datagram(sd_event_source *es, int fd, uint32_t revents, void *userdata);
222 void server_space_usage_message(Server *s, JournalStorage *storage);
223
224 int server_start_or_stop_idle_timer(Server *s);
225 int server_refresh_idle_timer(Server *s);