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