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