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