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