1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
6 This file is part of systemd.
8 Copyright 2011 Lennart Poettering
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.
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.
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/>.
26 #include <sys/epoll.h>
27 #include <sys/types.h>
28 #include <sys/socket.h>
31 #include "journal-file.h"
35 #include "journald-rate-limit.h"
38 typedef enum Storage {
47 typedef enum SplitMode {
55 typedef struct StdoutStream StdoutStream;
57 typedef struct Server {
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 *sync_event_source;
70 sd_event_source *sigusr1_event_source;
71 sd_event_source *sigusr2_event_source;
72 sd_event_source *sigterm_event_source;
73 sd_event_source *sigint_event_source;
75 JournalFile *runtime_journal;
76 JournalFile *system_journal;
77 Hashmap *user_journals;
84 JournalRateLimit *rate_limit;
85 usec_t sync_interval_usec;
86 usec_t rate_limit_interval;
87 unsigned rate_limit_burst;
89 JournalMetrics runtime_metrics;
90 JournalMetrics system_metrics;
96 bool forward_to_syslog;
97 bool forward_to_console;
99 unsigned n_forward_syslog_missed;
100 usec_t last_warn_forward_syslog_missed;
102 uint64_t cached_available_space;
103 usec_t cached_available_space_timestamp;
105 uint64_t var_available_timestamp;
107 usec_t max_retention_usec;
108 usec_t max_file_usec;
109 usec_t oldest_file_usec;
111 LIST_HEAD(StdoutStream, stdout_streams);
112 unsigned n_stdout_streams;
117 int max_level_syslog;
119 int max_level_console;
122 SplitMode split_mode;
126 bool dev_kmsg_readable;
128 uint64_t *kernel_seqnum;
135 #define N_IOVEC_META_FIELDS 20
136 #define N_IOVEC_KERNEL_FIELDS 64
137 #define N_IOVEC_UDEV_FIELDS 32
138 #define N_IOVEC_OBJECT_FIELDS 11
140 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);
141 void server_driver_message(Server *s, sd_id128_t message_id, const char *format, ...) _printf_(3,4);
143 /* gperf lookup function */
144 const struct ConfigPerfItem* journald_gperf_lookup(const char *key, unsigned length);
146 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);
148 const char *storage_to_string(Storage s) _const_;
149 Storage storage_from_string(const char *s) _pure_;
151 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);
153 const char *split_mode_to_string(SplitMode s) _const_;
154 SplitMode split_mode_from_string(const char *s) _pure_;
156 void server_fix_perms(Server *s, JournalFile *f, uid_t uid);
157 bool shall_try_append_again(JournalFile *f, int r);
158 int server_init(Server *s);
159 void server_done(Server *s);
160 void server_sync(Server *s);
161 void server_vacuum(Server *s);
162 void server_rotate(Server *s);
163 int server_schedule_sync(Server *s, int priority);
164 int server_flush_to_var(Server *s);
165 void server_maybe_append_tags(Server *s);
166 int process_datagram(sd_event_source *es, int fd, uint32_t revents, void *userdata);