]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/journal/journald-server.h
f0076793e183566e315cbe810e08311b0d4b2d52
[thirdparty/systemd.git] / src / journal / journald-server.h
1 #pragma once
2
3 /***
4 This file is part of systemd.
5
6 Copyright 2011 Lennart Poettering
7
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.
12
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.
17
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/>.
20 ***/
21
22 #include <stdbool.h>
23 #include <sys/types.h>
24
25 #include "sd-event.h"
26
27 typedef struct Server Server;
28
29 #include "hashmap.h"
30 #include "journal-file.h"
31 #include "journald-context.h"
32 #include "journald-rate-limit.h"
33 #include "journald-stream.h"
34 #include "list.h"
35 #include "prioq.h"
36
37 typedef enum Storage {
38 STORAGE_AUTO,
39 STORAGE_VOLATILE,
40 STORAGE_PERSISTENT,
41 STORAGE_NONE,
42 _STORAGE_MAX,
43 _STORAGE_INVALID = -1
44 } Storage;
45
46 typedef enum SplitMode {
47 SPLIT_UID,
48 SPLIT_LOGIN, /* deprecated */
49 SPLIT_NONE,
50 _SPLIT_MAX,
51 _SPLIT_INVALID = -1
52 } SplitMode;
53
54 typedef struct JournalStorageSpace {
55 usec_t timestamp;
56
57 uint64_t available;
58 uint64_t limit;
59
60 uint64_t vfs_used; /* space used by journal files */
61 uint64_t vfs_available;
62 } JournalStorageSpace;
63
64 typedef struct JournalStorage {
65 const char *name;
66 char *path;
67
68 JournalMetrics metrics;
69 JournalStorageSpace space;
70 } JournalStorage;
71
72 struct Server {
73 int syslog_fd;
74 int native_fd;
75 int stdout_fd;
76 int dev_kmsg_fd;
77 int audit_fd;
78 int hostname_fd;
79 int notify_fd;
80
81 sd_event *event;
82
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;
97
98 JournalFile *runtime_journal;
99 JournalFile *system_journal;
100 OrderedHashmap *user_journals;
101
102 uint64_t seqnum;
103
104 char *buffer;
105 size_t buffer_size;
106
107 JournalRateLimit *rate_limit;
108 usec_t sync_interval_usec;
109 usec_t rate_limit_interval;
110 unsigned rate_limit_burst;
111
112 JournalStorage runtime_storage;
113 JournalStorage system_storage;
114
115 bool compress;
116 bool seal;
117 bool read_kmsg;
118
119 bool forward_to_kmsg;
120 bool forward_to_syslog;
121 bool forward_to_console;
122 bool forward_to_wall;
123
124 unsigned n_forward_syslog_missed;
125 usec_t last_warn_forward_syslog_missed;
126
127 uint64_t var_available_timestamp;
128
129 usec_t max_retention_usec;
130 usec_t max_file_usec;
131 usec_t oldest_file_usec;
132
133 LIST_HEAD(StdoutStream, stdout_streams);
134 LIST_HEAD(StdoutStream, stdout_streams_notify_queue);
135 unsigned n_stdout_streams;
136
137 char *tty_path;
138
139 int max_level_store;
140 int max_level_syslog;
141 int max_level_kmsg;
142 int max_level_console;
143 int max_level_wall;
144
145 Storage storage;
146 SplitMode split_mode;
147
148 MMapCache *mmap;
149
150 Set *deferred_closes;
151
152 struct udev *udev;
153
154 uint64_t *kernel_seqnum;
155 bool dev_kmsg_readable:1;
156
157 bool send_watchdog:1;
158 bool sent_notify_ready:1;
159 bool sync_scheduled:1;
160
161 char machine_id_field[sizeof("_MACHINE_ID=") + 32];
162 char boot_id_field[sizeof("_BOOT_ID=") + 32];
163 char *hostname_field;
164
165 /* Cached cgroup root, so that we don't have to query that all the time */
166 char *cgroup_root;
167
168 usec_t watchdog_usec;
169
170 usec_t last_realtime_clock;
171
172 size_t line_max;
173
174 /* Caching of client metadata */
175 Hashmap *client_contexts;
176 Prioq *client_contexts_lru;
177
178 ClientContext *my_context; /* the context of journald itself */
179 ClientContext *pid1_context; /* the context of PID 1 */
180 };
181
182 #define SERVER_MACHINE_ID(s) ((s)->machine_id_field + strlen("_MACHINE_ID="))
183
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
189
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_;
192
193 /* gperf lookup function */
194 const struct ConfigPerfItem* journald_gperf_lookup(const char *key, GPERF_LEN_TYPE length);
195
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);
198
199 const char *storage_to_string(Storage s) _const_;
200 Storage storage_from_string(const char *s) _pure_;
201
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);
203
204 const char *split_mode_to_string(SplitMode s) _const_;
205 SplitMode split_mode_from_string(const char *s) _pure_;
206
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);