1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
9 typedef struct Server Server
;
11 #include "conf-parser.h"
13 #include "journald-context.h"
14 #include "journald-rate-limit.h"
15 #include "journald-stream.h"
17 #include "managed-journal-file.h"
19 #include "ratelimit.h"
20 #include "time-util.h"
23 #define JOURNALD_LOG_RATELIMIT ((RateLimit) { .interval = 60 * USEC_PER_SEC, .burst = 3 })
25 typedef enum Storage
{
31 _STORAGE_INVALID
= -EINVAL
,
34 typedef enum SplitMode
{
36 SPLIT_LOGIN
, /* deprecated */
39 _SPLIT_INVALID
= -EINVAL
,
42 typedef struct JournalCompressOptions
{
44 uint64_t threshold_bytes
;
45 } JournalCompressOptions
;
47 typedef struct JournalStorageSpace
{
53 uint64_t vfs_used
; /* space used by journal files */
54 uint64_t vfs_available
;
55 } JournalStorageSpace
;
57 typedef struct JournalStorage
{
61 JournalMetrics metrics
;
62 JournalStorageSpace space
;
78 sd_event_source
*syslog_event_source
;
79 sd_event_source
*native_event_source
;
80 sd_event_source
*stdout_event_source
;
81 sd_event_source
*dev_kmsg_event_source
;
82 sd_event_source
*audit_event_source
;
83 sd_event_source
*sync_event_source
;
84 sd_event_source
*sigusr1_event_source
;
85 sd_event_source
*sigusr2_event_source
;
86 sd_event_source
*sigterm_event_source
;
87 sd_event_source
*sigint_event_source
;
88 sd_event_source
*sigrtmin1_event_source
;
89 sd_event_source
*hostname_event_source
;
90 sd_event_source
*notify_event_source
;
91 sd_event_source
*watchdog_event_source
;
92 sd_event_source
*idle_event_source
;
94 ManagedJournalFile
*runtime_journal
;
95 ManagedJournalFile
*system_journal
;
96 OrderedHashmap
*user_journals
;
102 JournalRateLimit
*ratelimit
;
103 usec_t sync_interval_usec
;
104 usec_t ratelimit_interval
;
105 unsigned ratelimit_burst
;
107 JournalStorage runtime_storage
;
108 JournalStorage system_storage
;
110 JournalCompressOptions compress
;
115 bool forward_to_kmsg
;
116 bool forward_to_syslog
;
117 bool forward_to_console
;
118 bool forward_to_wall
;
120 unsigned n_forward_syslog_missed
;
121 usec_t last_warn_forward_syslog_missed
;
123 usec_t max_retention_usec
;
124 usec_t max_file_usec
;
125 usec_t oldest_file_usec
;
127 LIST_HEAD(StdoutStream
, stdout_streams
);
128 LIST_HEAD(StdoutStream
, stdout_streams_notify_queue
);
129 unsigned n_stdout_streams
;
134 int max_level_syslog
;
136 int max_level_console
;
140 SplitMode split_mode
;
144 Set
*deferred_closes
;
146 uint64_t *kernel_seqnum
;
147 bool dev_kmsg_readable
:1;
148 RateLimit kmsg_own_ratelimit
;
150 bool send_watchdog
:1;
151 bool sent_notify_ready
:1;
152 bool sync_scheduled
:1;
154 char machine_id_field
[sizeof("_MACHINE_ID=") + 32];
155 char boot_id_field
[sizeof("_BOOT_ID=") + 32];
156 char *hostname_field
;
157 char *namespace_field
;
158 char *runtime_directory
;
160 /* Cached cgroup root, so that we don't have to query that all the time */
163 usec_t watchdog_usec
;
165 usec_t last_realtime_clock
;
169 /* Caching of client metadata */
170 Hashmap
*client_contexts
;
171 Prioq
*client_contexts_lru
;
173 usec_t last_cache_pid_flush
;
175 ClientContext
*my_context
; /* the context of journald itself */
176 ClientContext
*pid1_context
; /* the context of PID 1 */
178 VarlinkServer
*varlink_server
;
181 #define SERVER_MACHINE_ID(s) ((s)->machine_id_field + STRLEN("_MACHINE_ID="))
183 /* Extra fields for any log messages */
184 #define N_IOVEC_META_FIELDS 24
186 /* Extra fields for log messages that contain OBJECT_PID= (i.e. log about another process) */
187 #define N_IOVEC_OBJECT_FIELDS 18
189 /* Maximum number of fields we'll add in for driver (i.e. internal) messages */
190 #define N_IOVEC_PAYLOAD_FIELDS 16
192 /* kmsg: Maximum number of extra fields we'll import from the kernel's /dev/kmsg */
193 #define N_IOVEC_KERNEL_FIELDS 64
195 /* kmsg: Maximum number of extra fields we'll import from udev's devices */
196 #define N_IOVEC_UDEV_FIELDS 32
198 /* audit: Maximum number of extra fields we'll import from audit messages */
199 #define N_IOVEC_AUDIT_FIELDS 64
201 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
);
202 void server_driver_message(Server
*s
, pid_t object_pid
, const char *message_id
, const char *format
, ...) _sentinel_
_printf_(4,0);
204 /* gperf lookup function */
205 const struct ConfigPerfItem
* journald_gperf_lookup(const char *key
, GPERF_LEN_TYPE length
);
207 CONFIG_PARSER_PROTOTYPE(config_parse_storage
);
208 CONFIG_PARSER_PROTOTYPE(config_parse_line_max
);
209 CONFIG_PARSER_PROTOTYPE(config_parse_compress
);
211 const char *storage_to_string(Storage s
) _const_
;
212 Storage
storage_from_string(const char *s
) _pure_
;
214 CONFIG_PARSER_PROTOTYPE(config_parse_split_mode
);
216 const char *split_mode_to_string(SplitMode s
) _const_
;
217 SplitMode
split_mode_from_string(const char *s
) _pure_
;
219 int server_init(Server
*s
, const char *namespace);
220 void server_done(Server
*s
);
221 void server_sync(Server
*s
);
222 void server_vacuum(Server
*s
, bool verbose
);
223 void server_rotate(Server
*s
);
224 int server_schedule_sync(Server
*s
, int priority
);
225 int server_flush_to_var(Server
*s
, bool require_flag_file
);
226 void server_maybe_append_tags(Server
*s
);
227 int server_process_datagram(sd_event_source
*es
, int fd
, uint32_t revents
, void *userdata
);
228 void server_space_usage_message(Server
*s
, JournalStorage
*storage
);
230 int server_start_or_stop_idle_timer(Server
*s
);
231 int server_refresh_idle_timer(Server
*s
);