]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
c2f1db8f | 2 | #pragma once |
e6960940 LP |
3 | |
4 | /*** | |
5 | This file is part of systemd. | |
6 | ||
7 | Copyright 2011 Lennart Poettering | |
8 | ||
9 | systemd is free software; you can redistribute it and/or modify it | |
5430f7f2 LP |
10 | under the terms of the GNU Lesser General Public License as published by |
11 | the Free Software Foundation; either version 2.1 of the License, or | |
e6960940 LP |
12 | (at your option) any later version. |
13 | ||
14 | systemd is distributed in the hope that it will be useful, but | |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
5430f7f2 | 17 | Lesser General Public License for more details. |
e6960940 | 18 | |
5430f7f2 | 19 | You should have received a copy of the GNU Lesser General Public License |
e6960940 LP |
20 | along with systemd; If not, see <http://www.gnu.org/licenses/>. |
21 | ***/ | |
22 | ||
e6960940 | 23 | #include <stdbool.h> |
b1bafc00 | 24 | #include <sys/types.h> |
e6960940 | 25 | |
f9a810be | 26 | #include "sd-event.h" |
430f0182 | 27 | |
e22aa3d3 LP |
28 | typedef struct Server Server; |
29 | ||
e6960940 | 30 | #include "hashmap.h" |
430f0182 | 31 | #include "journal-file.h" |
22e3a02b | 32 | #include "journald-context.h" |
d2bd7630 | 33 | #include "journald-rate-limit.h" |
e22aa3d3 | 34 | #include "journald-stream.h" |
e6960940 | 35 | #include "list.h" |
22e3a02b | 36 | #include "prioq.h" |
e6960940 | 37 | |
e156d769 LP |
38 | typedef enum Storage { |
39 | STORAGE_AUTO, | |
40 | STORAGE_VOLATILE, | |
205c4d1d | 41 | STORAGE_PERSISTENT, |
e156d769 LP |
42 | STORAGE_NONE, |
43 | _STORAGE_MAX, | |
44 | _STORAGE_INVALID = -1 | |
45 | } Storage; | |
46 | ||
182b858f | 47 | typedef enum SplitMode { |
182b858f | 48 | SPLIT_UID, |
76153ad4 | 49 | SPLIT_LOGIN, /* deprecated */ |
182b858f LP |
50 | SPLIT_NONE, |
51 | _SPLIT_MAX, | |
52 | _SPLIT_INVALID = -1 | |
53 | } SplitMode; | |
54 | ||
266a4700 | 55 | typedef struct JournalStorageSpace { |
23aba343 FB |
56 | usec_t timestamp; |
57 | ||
266a4700 FB |
58 | uint64_t available; |
59 | uint64_t limit; | |
23aba343 FB |
60 | |
61 | uint64_t vfs_used; /* space used by journal files */ | |
62 | uint64_t vfs_available; | |
266a4700 FB |
63 | } JournalStorageSpace; |
64 | ||
65 | typedef struct JournalStorage { | |
66 | const char *name; | |
c6e9e16f | 67 | char *path; |
266a4700 FB |
68 | |
69 | JournalMetrics metrics; | |
70 | JournalStorageSpace space; | |
71 | } JournalStorage; | |
72 | ||
e22aa3d3 | 73 | struct Server { |
e6960940 LP |
74 | int syslog_fd; |
75 | int native_fd; | |
76 | int stdout_fd; | |
51abe64c | 77 | int dev_kmsg_fd; |
875c2e22 | 78 | int audit_fd; |
0c24bb23 | 79 | int hostname_fd; |
e22aa3d3 | 80 | int notify_fd; |
e6960940 | 81 | |
f9a810be LP |
82 | sd_event *event; |
83 | ||
84 | sd_event_source *syslog_event_source; | |
85 | sd_event_source *native_event_source; | |
86 | sd_event_source *stdout_event_source; | |
87 | sd_event_source *dev_kmsg_event_source; | |
875c2e22 | 88 | sd_event_source *audit_event_source; |
f9a810be LP |
89 | sd_event_source *sync_event_source; |
90 | sd_event_source *sigusr1_event_source; | |
91 | sd_event_source *sigusr2_event_source; | |
92 | sd_event_source *sigterm_event_source; | |
93 | sd_event_source *sigint_event_source; | |
94b65516 | 94 | sd_event_source *sigrtmin1_event_source; |
0c24bb23 | 95 | sd_event_source *hostname_event_source; |
e22aa3d3 | 96 | sd_event_source *notify_event_source; |
119e9655 | 97 | sd_event_source *watchdog_event_source; |
f9a810be | 98 | |
e6960940 LP |
99 | JournalFile *runtime_journal; |
100 | JournalFile *system_journal; | |
43cf8388 | 101 | OrderedHashmap *user_journals; |
e6960940 LP |
102 | |
103 | uint64_t seqnum; | |
104 | ||
105 | char *buffer; | |
106 | size_t buffer_size; | |
107 | ||
108 | JournalRateLimit *rate_limit; | |
26687bf8 | 109 | usec_t sync_interval_usec; |
e6960940 LP |
110 | usec_t rate_limit_interval; |
111 | unsigned rate_limit_burst; | |
112 | ||
266a4700 FB |
113 | JournalStorage runtime_storage; |
114 | JournalStorage system_storage; | |
e6960940 LP |
115 | |
116 | bool compress; | |
eb53b74f | 117 | bool seal; |
b2392ff3 | 118 | bool read_kmsg; |
e6960940 | 119 | |
224f2ee2 LP |
120 | bool forward_to_kmsg; |
121 | bool forward_to_syslog; | |
122 | bool forward_to_console; | |
40b71e89 | 123 | bool forward_to_wall; |
224f2ee2 | 124 | |
178cc770 LP |
125 | unsigned n_forward_syslog_missed; |
126 | usec_t last_warn_forward_syslog_missed; | |
127 | ||
e6960940 LP |
128 | uint64_t var_available_timestamp; |
129 | ||
fb0951b0 LP |
130 | usec_t max_retention_usec; |
131 | usec_t max_file_usec; | |
132 | usec_t oldest_file_usec; | |
133 | ||
e6960940 | 134 | LIST_HEAD(StdoutStream, stdout_streams); |
e22aa3d3 | 135 | LIST_HEAD(StdoutStream, stdout_streams_notify_queue); |
e6960940 | 136 | unsigned n_stdout_streams; |
0d9243f0 LP |
137 | |
138 | char *tty_path; | |
213ba152 LP |
139 | |
140 | int max_level_store; | |
141 | int max_level_syslog; | |
142 | int max_level_kmsg; | |
143 | int max_level_console; | |
40b71e89 | 144 | int max_level_wall; |
e156d769 LP |
145 | |
146 | Storage storage; | |
182b858f | 147 | SplitMode split_mode; |
51abe64c | 148 | |
16e9f408 LP |
149 | MMapCache *mmap; |
150 | ||
b58c888f VC |
151 | Set *deferred_closes; |
152 | ||
119e9655 | 153 | struct udev *udev; |
cee5e9a7 LP |
154 | |
155 | uint64_t *kernel_seqnum; | |
119e9655 | 156 | bool dev_kmsg_readable:1; |
bdfb9e7f | 157 | |
119e9655 LP |
158 | bool send_watchdog:1; |
159 | bool sent_notify_ready:1; | |
160 | bool sync_scheduled:1; | |
0c24bb23 LP |
161 | |
162 | char machine_id_field[sizeof("_MACHINE_ID=") + 32]; | |
163 | char boot_id_field[sizeof("_BOOT_ID=") + 32]; | |
164 | char *hostname_field; | |
e9174f29 LP |
165 | |
166 | /* Cached cgroup root, so that we don't have to query that all the time */ | |
167 | char *cgroup_root; | |
119e9655 LP |
168 | |
169 | usec_t watchdog_usec; | |
7c070017 LP |
170 | |
171 | usec_t last_realtime_clock; | |
22e3a02b | 172 | |
ec20fe5f LP |
173 | size_t line_max; |
174 | ||
22e3a02b LP |
175 | /* Caching of client metadata */ |
176 | Hashmap *client_contexts; | |
177 | Prioq *client_contexts_lru; | |
178 | ||
179 | ClientContext *my_context; /* the context of journald itself */ | |
180 | ClientContext *pid1_context; /* the context of PID 1 */ | |
e22aa3d3 | 181 | }; |
e6960940 | 182 | |
8580d1f7 LP |
183 | #define SERVER_MACHINE_ID(s) ((s)->machine_id_field + strlen("_MACHINE_ID=")) |
184 | ||
4b58153d | 185 | #define N_IOVEC_META_FIELDS 22 |
ef63833d LP |
186 | #define N_IOVEC_KERNEL_FIELDS 64 |
187 | #define N_IOVEC_UDEV_FIELDS 32 | |
d473176a | 188 | #define N_IOVEC_OBJECT_FIELDS 14 |
282c5c4e | 189 | #define N_IOVEC_PAYLOAD_FIELDS 15 |
ef63833d | 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); |
13181942 | 192 | void server_driver_message(Server *s, pid_t object_pid, const char *message_id, const char *format, ...) _sentinel_; |
ef63833d | 193 | |
e6960940 | 194 | /* gperf lookup function */ |
c9f7b4d3 | 195 | const struct ConfigPerfItem* journald_gperf_lookup(const char *key, GPERF_LEN_TYPE length); |
e6960940 | 196 | |
71a61510 | 197 | int config_parse_storage(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); |
ec20fe5f | 198 | int config_parse_line_max(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); |
e156d769 | 199 | |
44a6b1b6 ZJS |
200 | const char *storage_to_string(Storage s) _const_; |
201 | Storage storage_from_string(const char *s) _pure_; | |
182b858f | 202 | |
71a61510 | 203 | int config_parse_split_mode(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); |
182b858f | 204 | |
44a6b1b6 ZJS |
205 | const char *split_mode_to_string(SplitMode s) _const_; |
206 | SplitMode split_mode_from_string(const char *s) _pure_; | |
d025f1e4 | 207 | |
d025f1e4 ZJS |
208 | int server_init(Server *s); |
209 | void server_done(Server *s); | |
26687bf8 | 210 | void server_sync(Server *s); |
3a19f215 | 211 | int server_vacuum(Server *s, bool verbose); |
d025f1e4 | 212 | void server_rotate(Server *s); |
d07f7b9e | 213 | int server_schedule_sync(Server *s, int priority); |
f78273c8 | 214 | int server_flush_to_var(Server *s, bool require_flag_file); |
d025f1e4 | 215 | void server_maybe_append_tags(Server *s); |
8531ae70 | 216 | int server_process_datagram(sd_event_source *es, int fd, uint32_t revents, void *userdata); |
cba5629e | 217 | void server_space_usage_message(Server *s, JournalStorage *storage); |