]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/journal/journald-server.h
Merge pull request #1465 from teg/siphash24
[thirdparty/systemd.git] / src / journal / journald-server.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 #pragma once
4
5 /***
6 This file is part of systemd.
7
8 Copyright 2011 Lennart Poettering
9
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 ***/
23
24 #include <stdbool.h>
25 #include <sys/types.h>
26
27 #include "sd-event.h"
28 #include "journal-file.h"
29 #include "hashmap.h"
30 #include "audit.h"
31 #include "journald-rate-limit.h"
32 #include "list.h"
33
34 typedef enum Storage {
35 STORAGE_AUTO,
36 STORAGE_VOLATILE,
37 STORAGE_PERSISTENT,
38 STORAGE_NONE,
39 _STORAGE_MAX,
40 _STORAGE_INVALID = -1
41 } Storage;
42
43 typedef enum SplitMode {
44 SPLIT_UID,
45 SPLIT_LOGIN,
46 SPLIT_NONE,
47 _SPLIT_MAX,
48 _SPLIT_INVALID = -1
49 } SplitMode;
50
51 typedef struct StdoutStream StdoutStream;
52
53 typedef struct Server {
54 int syslog_fd;
55 int native_fd;
56 int stdout_fd;
57 int dev_kmsg_fd;
58 int audit_fd;
59 int hostname_fd;
60
61 sd_event *event;
62
63 sd_event_source *syslog_event_source;
64 sd_event_source *native_event_source;
65 sd_event_source *stdout_event_source;
66 sd_event_source *dev_kmsg_event_source;
67 sd_event_source *audit_event_source;
68 sd_event_source *sync_event_source;
69 sd_event_source *sigusr1_event_source;
70 sd_event_source *sigusr2_event_source;
71 sd_event_source *sigterm_event_source;
72 sd_event_source *sigint_event_source;
73 sd_event_source *hostname_event_source;
74
75 JournalFile *runtime_journal;
76 JournalFile *system_journal;
77 OrderedHashmap *user_journals;
78
79 uint64_t seqnum;
80
81 char *buffer;
82 size_t buffer_size;
83
84 JournalRateLimit *rate_limit;
85 usec_t sync_interval_usec;
86 usec_t rate_limit_interval;
87 unsigned rate_limit_burst;
88
89 JournalMetrics runtime_metrics;
90 JournalMetrics system_metrics;
91
92 bool compress;
93 bool seal;
94
95 bool forward_to_kmsg;
96 bool forward_to_syslog;
97 bool forward_to_console;
98 bool forward_to_wall;
99
100 unsigned n_forward_syslog_missed;
101 usec_t last_warn_forward_syslog_missed;
102
103 uint64_t cached_space_available;
104 uint64_t cached_space_limit;
105 usec_t cached_space_timestamp;
106
107 uint64_t var_available_timestamp;
108
109 usec_t max_retention_usec;
110 usec_t max_file_usec;
111 usec_t oldest_file_usec;
112
113 LIST_HEAD(StdoutStream, stdout_streams);
114 unsigned n_stdout_streams;
115
116 char *tty_path;
117
118 int max_level_store;
119 int max_level_syslog;
120 int max_level_kmsg;
121 int max_level_console;
122 int max_level_wall;
123
124 Storage storage;
125 SplitMode split_mode;
126
127 MMapCache *mmap;
128
129 bool dev_kmsg_readable;
130
131 uint64_t *kernel_seqnum;
132
133 struct udev *udev;
134
135 bool sync_scheduled;
136
137 char machine_id_field[sizeof("_MACHINE_ID=") + 32];
138 char boot_id_field[sizeof("_BOOT_ID=") + 32];
139 char *hostname_field;
140
141 /* Cached cgroup root, so that we don't have to query that all the time */
142 char *cgroup_root;
143 } Server;
144
145 #define SERVER_MACHINE_ID(s) ((s)->machine_id_field + strlen("_MACHINE_ID="))
146
147 #define N_IOVEC_META_FIELDS 20
148 #define N_IOVEC_KERNEL_FIELDS 64
149 #define N_IOVEC_UDEV_FIELDS 32
150 #define N_IOVEC_OBJECT_FIELDS 12
151
152 void server_dispatch_message(Server *s, struct iovec *iovec, unsigned n, unsigned m, const struct ucred *ucred, const struct timeval *tv, const char *label, size_t label_len, const char *unit_id, int priority, pid_t object_pid);
153 void server_driver_message(Server *s, sd_id128_t message_id, const char *format, ...) _printf_(3,4);
154
155 /* gperf lookup function */
156 const struct ConfigPerfItem* journald_gperf_lookup(const char *key, unsigned length);
157
158 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);
159
160 const char *storage_to_string(Storage s) _const_;
161 Storage storage_from_string(const char *s) _pure_;
162
163 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);
164
165 const char *split_mode_to_string(SplitMode s) _const_;
166 SplitMode split_mode_from_string(const char *s) _pure_;
167
168 void server_fix_perms(Server *s, JournalFile *f, uid_t uid);
169 int server_init(Server *s);
170 void server_done(Server *s);
171 void server_sync(Server *s);
172 int server_vacuum(Server *s, bool verbose, bool patch_min_use);
173 void server_rotate(Server *s);
174 int server_schedule_sync(Server *s, int priority);
175 int server_flush_to_var(Server *s);
176 void server_maybe_append_tags(Server *s);
177 int server_process_datagram(sd_event_source *es, int fd, uint32_t revents, void *userdata);