chiark / gitweb /
build-sys: store journald code in a noinst library
[elogind.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 <inttypes.h>
25 #include <stdbool.h>
26 #include <sys/epoll.h>
27 #include <sys/types.h>
28 #include <sys/socket.h>
29
30 #include "journal-file.h"
31 #include "hashmap.h"
32 #include "util.h"
33 #include "audit.h"
34 #include "journald-rate-limit.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_LOGIN,
48         SPLIT_UID,
49         SPLIT_NONE,
50         _SPLIT_MAX,
51         _SPLIT_INVALID = -1
52 } SplitMode;
53
54 typedef struct StdoutStream StdoutStream;
55
56 typedef struct Server {
57         int epoll_fd;
58         int signal_fd;
59         int syslog_fd;
60         int native_fd;
61         int stdout_fd;
62         int dev_kmsg_fd;
63
64         JournalFile *runtime_journal;
65         JournalFile *system_journal;
66         Hashmap *user_journals;
67
68         uint64_t seqnum;
69
70         char *buffer;
71         size_t buffer_size;
72
73         JournalRateLimit *rate_limit;
74         usec_t rate_limit_interval;
75         unsigned rate_limit_burst;
76
77         JournalMetrics runtime_metrics;
78         JournalMetrics system_metrics;
79
80         bool compress;
81         bool seal;
82
83         bool forward_to_kmsg;
84         bool forward_to_syslog;
85         bool forward_to_console;
86
87         unsigned n_forward_syslog_missed;
88         usec_t last_warn_forward_syslog_missed;
89
90         uint64_t cached_available_space;
91         usec_t cached_available_space_timestamp;
92
93         uint64_t var_available_timestamp;
94
95         usec_t max_retention_usec;
96         usec_t max_file_usec;
97         usec_t oldest_file_usec;
98
99         gid_t file_gid;
100         bool file_gid_valid;
101
102         LIST_HEAD(StdoutStream, stdout_streams);
103         unsigned n_stdout_streams;
104
105         char *tty_path;
106
107         int max_level_store;
108         int max_level_syslog;
109         int max_level_kmsg;
110         int max_level_console;
111
112         Storage storage;
113         SplitMode split_mode;
114
115         MMapCache *mmap;
116
117         bool dev_kmsg_readable;
118
119         uint64_t *kernel_seqnum;
120
121         struct udev *udev;
122 } Server;
123
124 #define N_IOVEC_META_FIELDS 17
125 #define N_IOVEC_KERNEL_FIELDS 64
126 #define N_IOVEC_UDEV_FIELDS 32
127
128 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);
129 void server_driver_message(Server *s, sd_id128_t message_id, const char *format, ...);
130
131 /* gperf lookup function */
132 const struct ConfigPerfItem* journald_gperf_lookup(const char *key, unsigned length);
133
134 int config_parse_storage(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
135
136 const char *storage_to_string(Storage s);
137 Storage storage_from_string(const char *s);
138
139 int config_parse_split_mode(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
140
141 const char *split_mode_to_string(SplitMode s);
142 SplitMode split_mode_from_string(const char *s);
143
144 void server_fix_perms(Server *s, JournalFile *f, uid_t uid);
145 bool shall_try_append_again(JournalFile *f, int r);
146 int server_init(Server *s);
147 void server_done(Server *s);
148 void server_vacuum(Server *s);
149 void server_rotate(Server *s);
150 int server_flush_to_var(Server *s);
151 int process_event(Server *s, struct epoll_event *ev);
152 void server_maybe_append_tags(Server *s);