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