]>
Commit | Line | Data |
---|---|---|
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 |
9 | typedef 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 |
22 | typedef enum Storage { |
23 | STORAGE_AUTO, | |
24 | STORAGE_VOLATILE, | |
205c4d1d | 25 | STORAGE_PERSISTENT, |
e156d769 LP |
26 | STORAGE_NONE, |
27 | _STORAGE_MAX, | |
28 | _STORAGE_INVALID = -1 | |
29 | } Storage; | |
30 | ||
182b858f | 31 | typedef enum SplitMode { |
182b858f | 32 | SPLIT_UID, |
76153ad4 | 33 | SPLIT_LOGIN, /* deprecated */ |
182b858f LP |
34 | SPLIT_NONE, |
35 | _SPLIT_MAX, | |
36 | _SPLIT_INVALID = -1 | |
37 | } SplitMode; | |
38 | ||
1b7cf0e5 AG |
39 | typedef struct JournalCompressOptions { |
40 | bool enabled; | |
41 | uint64_t threshold_bytes; | |
42 | } JournalCompressOptions; | |
43 | ||
266a4700 | 44 | typedef 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 | ||
54 | typedef struct JournalStorage { | |
55 | const char *name; | |
c6e9e16f | 56 | char *path; |
266a4700 FB |
57 | |
58 | JournalMetrics metrics; | |
59 | JournalStorageSpace space; | |
60 | } JournalStorage; | |
61 | ||
e22aa3d3 | 62 | struct 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; | |
98 | size_t buffer_size; | |
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; |
bdfb9e7f | 146 | |
119e9655 LP |
147 | bool send_watchdog:1; |
148 | bool sent_notify_ready:1; | |
149 | bool sync_scheduled:1; | |
0c24bb23 LP |
150 | |
151 | char machine_id_field[sizeof("_MACHINE_ID=") + 32]; | |
152 | char boot_id_field[sizeof("_BOOT_ID=") + 32]; | |
153 | char *hostname_field; | |
b1852c48 LP |
154 | char *namespace_field; |
155 | char *runtime_directory; | |
e9174f29 LP |
156 | |
157 | /* Cached cgroup root, so that we don't have to query that all the time */ | |
158 | char *cgroup_root; | |
119e9655 LP |
159 | |
160 | usec_t watchdog_usec; | |
7c070017 LP |
161 | |
162 | usec_t last_realtime_clock; | |
22e3a02b | 163 | |
ec20fe5f LP |
164 | size_t line_max; |
165 | ||
22e3a02b LP |
166 | /* Caching of client metadata */ |
167 | Hashmap *client_contexts; | |
168 | Prioq *client_contexts_lru; | |
169 | ||
91714a7f ZJS |
170 | usec_t last_cache_pid_flush; |
171 | ||
22e3a02b LP |
172 | ClientContext *my_context; /* the context of journald itself */ |
173 | ClientContext *pid1_context; /* the context of PID 1 */ | |
1ec23479 LP |
174 | |
175 | VarlinkServer *varlink_server; | |
e22aa3d3 | 176 | }; |
e6960940 | 177 | |
fbd0b64f | 178 | #define SERVER_MACHINE_ID(s) ((s)->machine_id_field + STRLEN("_MACHINE_ID=")) |
8580d1f7 | 179 | |
e61ad5c2 | 180 | /* Extra fields for any log messages */ |
b1852c48 | 181 | #define N_IOVEC_META_FIELDS 23 |
e61ad5c2 LP |
182 | |
183 | /* Extra fields for log messages that contain OBJECT_PID= (i.e. log about another process) */ | |
184 | #define N_IOVEC_OBJECT_FIELDS 18 | |
185 | ||
186 | /* Maximum number of fields we'll add in for driver (i.e. internal) messages */ | |
187 | #define N_IOVEC_PAYLOAD_FIELDS 16 | |
188 | ||
189 | /* kmsg: Maximum number of extra fields we'll import from the kernel's /dev/kmsg */ | |
ef63833d | 190 | #define N_IOVEC_KERNEL_FIELDS 64 |
e61ad5c2 LP |
191 | |
192 | /* kmsg: Maximum number of extra fields we'll import from udev's devices */ | |
ef63833d LP |
193 | #define N_IOVEC_UDEV_FIELDS 32 |
194 | ||
d3070fbd | 195 | 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 | 196 | void server_driver_message(Server *s, pid_t object_pid, const char *message_id, const char *format, ...) _sentinel_ _printf_(4,0); |
ef63833d | 197 | |
e6960940 | 198 | /* gperf lookup function */ |
c9f7b4d3 | 199 | const struct ConfigPerfItem* journald_gperf_lookup(const char *key, GPERF_LEN_TYPE length); |
e6960940 | 200 | |
a2106925 LP |
201 | CONFIG_PARSER_PROTOTYPE(config_parse_storage); |
202 | CONFIG_PARSER_PROTOTYPE(config_parse_line_max); | |
203 | CONFIG_PARSER_PROTOTYPE(config_parse_compress); | |
e156d769 | 204 | |
44a6b1b6 ZJS |
205 | const char *storage_to_string(Storage s) _const_; |
206 | Storage storage_from_string(const char *s) _pure_; | |
182b858f | 207 | |
a2106925 | 208 | CONFIG_PARSER_PROTOTYPE(config_parse_split_mode); |
182b858f | 209 | |
44a6b1b6 ZJS |
210 | const char *split_mode_to_string(SplitMode s) _const_; |
211 | SplitMode split_mode_from_string(const char *s) _pure_; | |
d025f1e4 | 212 | |
b1852c48 | 213 | int server_init(Server *s, const char *namespace); |
d025f1e4 | 214 | void server_done(Server *s); |
26687bf8 | 215 | void server_sync(Server *s); |
3a19f215 | 216 | int server_vacuum(Server *s, bool verbose); |
d025f1e4 | 217 | void server_rotate(Server *s); |
d07f7b9e | 218 | int server_schedule_sync(Server *s, int priority); |
f78273c8 | 219 | int server_flush_to_var(Server *s, bool require_flag_file); |
d025f1e4 | 220 | void server_maybe_append_tags(Server *s); |
8531ae70 | 221 | int server_process_datagram(sd_event_source *es, int fd, uint32_t revents, void *userdata); |
cba5629e | 222 | void server_space_usage_message(Server *s, JournalStorage *storage); |
65c398c0 LP |
223 | |
224 | int server_start_or_stop_idle_timer(Server *s); | |
225 | int server_refresh_idle_timer(Server *s); |