]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/journal/journald-server.h
tty-ask-password: Split out password sending
[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
29 typedef struct Server Server;
30
31 #include "hashmap.h"
32 #include "journal-file.h"
33 #include "journald-rate-limit.h"
34 #include "journald-stream.h"
35 #include "list.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,
49 SPLIT_NONE,
50 _SPLIT_MAX,
51 _SPLIT_INVALID = -1
52 } SplitMode;
53
54 struct Server {
55 int syslog_fd;
56 int native_fd;
57 int stdout_fd;
58 int dev_kmsg_fd;
59 int audit_fd;
60 int hostname_fd;
61 int notify_fd;
62
63 sd_event *event;
64
65 sd_event_source *syslog_event_source;
66 sd_event_source *native_event_source;
67 sd_event_source *stdout_event_source;
68 sd_event_source *dev_kmsg_event_source;
69 sd_event_source *audit_event_source;
70 sd_event_source *sync_event_source;
71 sd_event_source *sigusr1_event_source;
72 sd_event_source *sigusr2_event_source;
73 sd_event_source *sigterm_event_source;
74 sd_event_source *sigint_event_source;
75 sd_event_source *sigrtmin1_event_source;
76 sd_event_source *hostname_event_source;
77 sd_event_source *notify_event_source;
78 sd_event_source *watchdog_event_source;
79
80 JournalFile *runtime_journal;
81 JournalFile *system_journal;
82 OrderedHashmap *user_journals;
83
84 uint64_t seqnum;
85
86 char *buffer;
87 size_t buffer_size;
88
89 JournalRateLimit *rate_limit;
90 usec_t sync_interval_usec;
91 usec_t rate_limit_interval;
92 unsigned rate_limit_burst;
93
94 JournalMetrics runtime_metrics;
95 JournalMetrics system_metrics;
96
97 bool compress;
98 bool seal;
99
100 bool forward_to_kmsg;
101 bool forward_to_syslog;
102 bool forward_to_console;
103 bool forward_to_wall;
104
105 unsigned n_forward_syslog_missed;
106 usec_t last_warn_forward_syslog_missed;
107
108 uint64_t cached_space_available;
109 uint64_t cached_space_limit;
110 usec_t cached_space_timestamp;
111
112 uint64_t var_available_timestamp;
113
114 usec_t max_retention_usec;
115 usec_t max_file_usec;
116 usec_t oldest_file_usec;
117
118 LIST_HEAD(StdoutStream, stdout_streams);
119 LIST_HEAD(StdoutStream, stdout_streams_notify_queue);
120 unsigned n_stdout_streams;
121
122 char *tty_path;
123
124 int max_level_store;
125 int max_level_syslog;
126 int max_level_kmsg;
127 int max_level_console;
128 int max_level_wall;
129
130 Storage storage;
131 SplitMode split_mode;
132
133 MMapCache *mmap;
134
135 struct udev *udev;
136
137 uint64_t *kernel_seqnum;
138 bool dev_kmsg_readable:1;
139
140 bool send_watchdog:1;
141 bool sent_notify_ready:1;
142 bool sync_scheduled:1;
143
144 char machine_id_field[sizeof("_MACHINE_ID=") + 32];
145 char boot_id_field[sizeof("_BOOT_ID=") + 32];
146 char *hostname_field;
147
148 /* Cached cgroup root, so that we don't have to query that all the time */
149 char *cgroup_root;
150
151 usec_t watchdog_usec;
152 };
153
154 #define SERVER_MACHINE_ID(s) ((s)->machine_id_field + strlen("_MACHINE_ID="))
155
156 #define N_IOVEC_META_FIELDS 20
157 #define N_IOVEC_KERNEL_FIELDS 64
158 #define N_IOVEC_UDEV_FIELDS 32
159 #define N_IOVEC_OBJECT_FIELDS 12
160 #define N_IOVEC_PAYLOAD_FIELDS 15
161
162 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);
163 void server_driver_message(Server *s, sd_id128_t message_id, const char *format, ...) _printf_(3,0) _sentinel_;
164
165 /* gperf lookup function */
166 const struct ConfigPerfItem* journald_gperf_lookup(const char *key, unsigned length);
167
168 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);
169
170 const char *storage_to_string(Storage s) _const_;
171 Storage storage_from_string(const char *s) _pure_;
172
173 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);
174
175 const char *split_mode_to_string(SplitMode s) _const_;
176 SplitMode split_mode_from_string(const char *s) _pure_;
177
178 int server_init(Server *s);
179 void server_done(Server *s);
180 void server_sync(Server *s);
181 int server_vacuum(Server *s, bool verbose, bool patch_min_use);
182 void server_rotate(Server *s);
183 int server_schedule_sync(Server *s, int priority);
184 int server_flush_to_var(Server *s);
185 void server_maybe_append_tags(Server *s);
186 int server_process_datagram(sd_event_source *es, int fd, uint32_t revents, void *userdata);