4 This file is part of systemd.
6 Copyright 2011 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
23 #include <sys/types.h>
27 typedef struct Server Server
;
30 #include "journal-file.h"
31 #include "journald-context.h"
32 #include "journald-rate-limit.h"
33 #include "journald-stream.h"
37 typedef enum Storage
{
46 typedef enum SplitMode
{
48 SPLIT_LOGIN
, /* deprecated */
54 typedef struct JournalStorageSpace
{
60 uint64_t vfs_used
; /* space used by journal files */
61 uint64_t vfs_available
;
62 } JournalStorageSpace
;
64 typedef struct JournalStorage
{
68 JournalMetrics metrics
;
69 JournalStorageSpace space
;
83 sd_event_source
*syslog_event_source
;
84 sd_event_source
*native_event_source
;
85 sd_event_source
*stdout_event_source
;
86 sd_event_source
*dev_kmsg_event_source
;
87 sd_event_source
*audit_event_source
;
88 sd_event_source
*sync_event_source
;
89 sd_event_source
*sigusr1_event_source
;
90 sd_event_source
*sigusr2_event_source
;
91 sd_event_source
*sigterm_event_source
;
92 sd_event_source
*sigint_event_source
;
93 sd_event_source
*sigrtmin1_event_source
;
94 sd_event_source
*hostname_event_source
;
95 sd_event_source
*notify_event_source
;
96 sd_event_source
*watchdog_event_source
;
98 JournalFile
*runtime_journal
;
99 JournalFile
*system_journal
;
100 OrderedHashmap
*user_journals
;
107 JournalRateLimit
*rate_limit
;
108 usec_t sync_interval_usec
;
109 usec_t rate_limit_interval
;
110 unsigned rate_limit_burst
;
112 JournalStorage runtime_storage
;
113 JournalStorage system_storage
;
119 bool forward_to_kmsg
;
120 bool forward_to_syslog
;
121 bool forward_to_console
;
122 bool forward_to_wall
;
124 unsigned n_forward_syslog_missed
;
125 usec_t last_warn_forward_syslog_missed
;
127 uint64_t var_available_timestamp
;
129 usec_t max_retention_usec
;
130 usec_t max_file_usec
;
131 usec_t oldest_file_usec
;
133 LIST_HEAD(StdoutStream
, stdout_streams
);
134 LIST_HEAD(StdoutStream
, stdout_streams_notify_queue
);
135 unsigned n_stdout_streams
;
140 int max_level_syslog
;
142 int max_level_console
;
146 SplitMode split_mode
;
150 Set
*deferred_closes
;
154 uint64_t *kernel_seqnum
;
155 bool dev_kmsg_readable
:1;
157 bool send_watchdog
:1;
158 bool sent_notify_ready
:1;
159 bool sync_scheduled
:1;
161 char machine_id_field
[sizeof("_MACHINE_ID=") + 32];
162 char boot_id_field
[sizeof("_BOOT_ID=") + 32];
163 char *hostname_field
;
165 /* Cached cgroup root, so that we don't have to query that all the time */
168 usec_t watchdog_usec
;
170 usec_t last_realtime_clock
;
174 /* Caching of client metadata */
175 Hashmap
*client_contexts
;
176 Prioq
*client_contexts_lru
;
178 ClientContext
*my_context
; /* the context of journald itself */
179 ClientContext
*pid1_context
; /* the context of PID 1 */
182 #define SERVER_MACHINE_ID(s) ((s)->machine_id_field + strlen("_MACHINE_ID="))
184 #define N_IOVEC_META_FIELDS 22
185 #define N_IOVEC_KERNEL_FIELDS 64
186 #define N_IOVEC_UDEV_FIELDS 32
187 #define N_IOVEC_OBJECT_FIELDS 14
188 #define N_IOVEC_PAYLOAD_FIELDS 15
190 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
);
191 void server_driver_message(Server
*s
, pid_t object_pid
, const char *message_id
, const char *format
, ...) _sentinel_
;
193 /* gperf lookup function */
194 const struct ConfigPerfItem
* journald_gperf_lookup(const char *key
, GPERF_LEN_TYPE length
);
196 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
);
197 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
);
199 const char *storage_to_string(Storage s
) _const_
;
200 Storage
storage_from_string(const char *s
) _pure_
;
202 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
);
204 const char *split_mode_to_string(SplitMode s
) _const_
;
205 SplitMode
split_mode_from_string(const char *s
) _pure_
;
207 int server_init(Server
*s
);
208 void server_done(Server
*s
);
209 void server_sync(Server
*s
);
210 int server_vacuum(Server
*s
, bool verbose
);
211 void server_rotate(Server
*s
);
212 int server_schedule_sync(Server
*s
, int priority
);
213 int server_flush_to_var(Server
*s
, bool require_flag_file
);
214 void server_maybe_append_tags(Server
*s
);
215 int server_process_datagram(sd_event_source
*es
, int fd
, uint32_t revents
, void *userdata
);
216 void server_space_usage_message(Server
*s
, JournalStorage
*storage
);