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