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 typedef enum Storage
{
29 _STORAGE_INVALID
= -EINVAL
,
32 typedef enum SplitMode
{
34 SPLIT_LOGIN
, /* deprecated */
37 _SPLIT_INVALID
= -EINVAL
,
40 typedef struct JournalCompressOptions
{
42 uint64_t threshold_bytes
;
43 } JournalCompressOptions
;
45 typedef struct JournalStorageSpace
{
51 uint64_t vfs_used
; /* space used by journal files */
52 uint64_t vfs_available
;
53 } JournalStorageSpace
;
55 typedef struct JournalStorage
{
59 JournalMetrics metrics
;
60 JournalStorageSpace space
;
76 sd_event_source
*syslog_event_source
;
77 sd_event_source
*native_event_source
;
78 sd_event_source
*stdout_event_source
;
79 sd_event_source
*dev_kmsg_event_source
;
80 sd_event_source
*audit_event_source
;
81 sd_event_source
*sync_event_source
;
82 sd_event_source
*sigusr1_event_source
;
83 sd_event_source
*sigusr2_event_source
;
84 sd_event_source
*sigterm_event_source
;
85 sd_event_source
*sigint_event_source
;
86 sd_event_source
*sigrtmin1_event_source
;
87 sd_event_source
*hostname_event_source
;
88 sd_event_source
*notify_event_source
;
89 sd_event_source
*watchdog_event_source
;
90 sd_event_source
*idle_event_source
;
92 ManagedJournalFile
*runtime_journal
;
93 ManagedJournalFile
*system_journal
;
94 OrderedHashmap
*user_journals
;
100 JournalRateLimit
*ratelimit
;
101 usec_t sync_interval_usec
;
102 usec_t ratelimit_interval
;
103 unsigned ratelimit_burst
;
105 JournalStorage runtime_storage
;
106 JournalStorage system_storage
;
108 JournalCompressOptions compress
;
113 bool forward_to_kmsg
;
114 bool forward_to_syslog
;
115 bool forward_to_console
;
116 bool forward_to_wall
;
118 unsigned n_forward_syslog_missed
;
119 usec_t last_warn_forward_syslog_missed
;
121 usec_t max_retention_usec
;
122 usec_t max_file_usec
;
123 usec_t oldest_file_usec
;
125 LIST_HEAD(StdoutStream
, stdout_streams
);
126 LIST_HEAD(StdoutStream
, stdout_streams_notify_queue
);
127 unsigned n_stdout_streams
;
132 int max_level_syslog
;
134 int max_level_console
;
138 SplitMode split_mode
;
142 Set
*deferred_closes
;
144 uint64_t *kernel_seqnum
;
145 bool dev_kmsg_readable
:1;
146 RateLimit kmsg_own_ratelimit
;
148 bool send_watchdog
:1;
149 bool sent_notify_ready
:1;
150 bool sync_scheduled
:1;
152 char machine_id_field
[sizeof("_MACHINE_ID=") + 32];
153 char boot_id_field
[sizeof("_BOOT_ID=") + 32];
154 char *hostname_field
;
155 char *namespace_field
;
156 char *runtime_directory
;
158 /* Cached cgroup root, so that we don't have to query that all the time */
161 usec_t watchdog_usec
;
163 usec_t last_realtime_clock
;
167 /* Caching of client metadata */
168 Hashmap
*client_contexts
;
169 Prioq
*client_contexts_lru
;
171 usec_t last_cache_pid_flush
;
173 ClientContext
*my_context
; /* the context of journald itself */
174 ClientContext
*pid1_context
; /* the context of PID 1 */
176 VarlinkServer
*varlink_server
;
179 #define SERVER_MACHINE_ID(s) ((s)->machine_id_field + STRLEN("_MACHINE_ID="))
181 /* Extra fields for any log messages */
182 #define N_IOVEC_META_FIELDS 23
184 /* Extra fields for log messages that contain OBJECT_PID= (i.e. log about another process) */
185 #define N_IOVEC_OBJECT_FIELDS 18
187 /* Maximum number of fields we'll add in for driver (i.e. internal) messages */
188 #define N_IOVEC_PAYLOAD_FIELDS 16
190 /* kmsg: Maximum number of extra fields we'll import from the kernel's /dev/kmsg */
191 #define N_IOVEC_KERNEL_FIELDS 64
193 /* kmsg: Maximum number of extra fields we'll import from udev's devices */
194 #define N_IOVEC_UDEV_FIELDS 32
196 /* audit: Maximum number of extra fields we'll import from audit messages */
197 #define N_IOVEC_AUDIT_FIELDS 64
199 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
);
200 void server_driver_message(Server
*s
, pid_t object_pid
, const char *message_id
, const char *format
, ...) _sentinel_
_printf_(4,0);
202 /* gperf lookup function */
203 const struct ConfigPerfItem
* journald_gperf_lookup(const char *key
, GPERF_LEN_TYPE length
);
205 CONFIG_PARSER_PROTOTYPE(config_parse_storage
);
206 CONFIG_PARSER_PROTOTYPE(config_parse_line_max
);
207 CONFIG_PARSER_PROTOTYPE(config_parse_compress
);
209 const char *storage_to_string(Storage s
) _const_
;
210 Storage
storage_from_string(const char *s
) _pure_
;
212 CONFIG_PARSER_PROTOTYPE(config_parse_split_mode
);
214 const char *split_mode_to_string(SplitMode s
) _const_
;
215 SplitMode
split_mode_from_string(const char *s
) _pure_
;
217 int server_init(Server
*s
, const char *namespace);
218 void server_done(Server
*s
);
219 void server_sync(Server
*s
);
220 void server_vacuum(Server
*s
, bool verbose
);
221 void server_rotate(Server
*s
);
222 int server_schedule_sync(Server
*s
, int priority
);
223 int server_flush_to_var(Server
*s
, bool require_flag_file
);
224 void server_maybe_append_tags(Server
*s
);
225 int server_process_datagram(sd_event_source
*es
, int fd
, uint32_t revents
, void *userdata
);
226 void server_space_usage_message(Server
*s
, JournalStorage
*storage
);
228 int server_start_or_stop_idle_timer(Server
*s
);
229 int server_refresh_idle_timer(Server
*s
);