]>
Commit | Line | Data |
---|---|---|
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 <inttypes.h> | |
25 | #include <stdbool.h> | |
26 | #include <sys/epoll.h> | |
27 | #include <sys/types.h> | |
28 | #include <sys/socket.h> | |
29 | ||
30 | #include "sd-event.h" | |
31 | #include "journal-file.h" | |
32 | #include "hashmap.h" | |
33 | #include "util.h" | |
34 | #include "audit.h" | |
35 | #include "journald-rate-limit.h" | |
36 | #include "list.h" | |
37 | ||
38 | typedef enum Storage { | |
39 | STORAGE_AUTO, | |
40 | STORAGE_VOLATILE, | |
41 | STORAGE_PERSISTENT, | |
42 | STORAGE_NONE, | |
43 | _STORAGE_MAX, | |
44 | _STORAGE_INVALID = -1 | |
45 | } Storage; | |
46 | ||
47 | typedef enum SplitMode { | |
48 | SPLIT_LOGIN, | |
49 | SPLIT_UID, | |
50 | SPLIT_NONE, | |
51 | _SPLIT_MAX, | |
52 | _SPLIT_INVALID = -1 | |
53 | } SplitMode; | |
54 | ||
55 | typedef struct StdoutStream StdoutStream; | |
56 | ||
57 | typedef struct Server { | |
58 | int syslog_fd; | |
59 | int native_fd; | |
60 | int stdout_fd; | |
61 | int dev_kmsg_fd; | |
62 | int hostname_fd; | |
63 | ||
64 | sd_event *event; | |
65 | ||
66 | sd_event_source *syslog_event_source; | |
67 | sd_event_source *native_event_source; | |
68 | sd_event_source *stdout_event_source; | |
69 | sd_event_source *dev_kmsg_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 *hostname_event_source; | |
76 | ||
77 | JournalFile *runtime_journal; | |
78 | JournalFile *system_journal; | |
79 | Hashmap *user_journals; | |
80 | ||
81 | uint64_t seqnum; | |
82 | ||
83 | char *buffer; | |
84 | size_t buffer_size; | |
85 | ||
86 | JournalRateLimit *rate_limit; | |
87 | usec_t sync_interval_usec; | |
88 | usec_t rate_limit_interval; | |
89 | unsigned rate_limit_burst; | |
90 | ||
91 | JournalMetrics runtime_metrics; | |
92 | JournalMetrics system_metrics; | |
93 | ||
94 | bool compress; | |
95 | bool seal; | |
96 | ||
97 | bool forward_to_kmsg; | |
98 | bool forward_to_syslog; | |
99 | bool forward_to_console; | |
100 | ||
101 | unsigned n_forward_syslog_missed; | |
102 | usec_t last_warn_forward_syslog_missed; | |
103 | ||
104 | uint64_t cached_available_space; | |
105 | usec_t cached_available_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 | ||
123 | Storage storage; | |
124 | SplitMode split_mode; | |
125 | ||
126 | MMapCache *mmap; | |
127 | ||
128 | bool dev_kmsg_readable; | |
129 | ||
130 | uint64_t *kernel_seqnum; | |
131 | ||
132 | struct udev *udev; | |
133 | ||
134 | bool sync_scheduled; | |
135 | ||
136 | char machine_id_field[sizeof("_MACHINE_ID=") + 32]; | |
137 | char boot_id_field[sizeof("_BOOT_ID=") + 32]; | |
138 | char *hostname_field; | |
139 | } Server; | |
140 | ||
141 | #define N_IOVEC_META_FIELDS 20 | |
142 | #define N_IOVEC_KERNEL_FIELDS 64 | |
143 | #define N_IOVEC_UDEV_FIELDS 32 | |
144 | #define N_IOVEC_OBJECT_FIELDS 11 | |
145 | ||
146 | void server_dispatch_message(Server *s, struct iovec *iovec, unsigned n, unsigned m, struct ucred *ucred, struct timeval *tv, const char *label, size_t label_len, const char *unit_id, int priority, pid_t object_pid); | |
147 | void server_driver_message(Server *s, sd_id128_t message_id, const char *format, ...) _printf_(3,4); | |
148 | ||
149 | /* gperf lookup function */ | |
150 | const struct ConfigPerfItem* journald_gperf_lookup(const char *key, unsigned length); | |
151 | ||
152 | 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); | |
153 | ||
154 | const char *storage_to_string(Storage s) _const_; | |
155 | Storage storage_from_string(const char *s) _pure_; | |
156 | ||
157 | 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); | |
158 | ||
159 | const char *split_mode_to_string(SplitMode s) _const_; | |
160 | SplitMode split_mode_from_string(const char *s) _pure_; | |
161 | ||
162 | void server_fix_perms(Server *s, JournalFile *f, uid_t uid); | |
163 | bool shall_try_append_again(JournalFile *f, int r); | |
164 | int server_init(Server *s); | |
165 | void server_done(Server *s); | |
166 | void server_sync(Server *s); | |
167 | void server_vacuum(Server *s); | |
168 | void server_rotate(Server *s); | |
169 | int server_schedule_sync(Server *s, int priority); | |
170 | int server_flush_to_var(Server *s); | |
171 | void server_maybe_append_tags(Server *s); | |
172 | int process_datagram(sd_event_source *es, int fd, uint32_t revents, void *userdata); |