2012-07-18 19:07:51 +02:00
|
|
|
#pragma once
|
2012-01-04 20:40:04 +01:00
|
|
|
|
|
|
|
/***
|
|
|
|
This file is part of systemd.
|
|
|
|
|
|
|
|
Copyright 2011 Lennart Poettering
|
|
|
|
|
|
|
|
systemd is free software; you can redistribute it and/or modify it
|
2012-04-12 00:20:58 +02:00
|
|
|
under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
2012-01-04 20:40:04 +01:00
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
systemd is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2012-04-12 00:20:58 +02:00
|
|
|
Lesser General Public License for more details.
|
2012-01-04 20:40:04 +01:00
|
|
|
|
2012-04-12 00:20:58 +02:00
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
2012-01-04 20:40:04 +01:00
|
|
|
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
***/
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
2012-10-13 18:09:09 +02:00
|
|
|
#include <sys/types.h>
|
2012-01-04 20:40:04 +01:00
|
|
|
|
2013-12-11 20:13:44 +01:00
|
|
|
#include "sd-event.h"
|
2015-10-26 23:32:16 +01:00
|
|
|
|
2015-11-01 21:50:24 +01:00
|
|
|
typedef struct Server Server;
|
|
|
|
|
2012-01-04 20:40:04 +01:00
|
|
|
#include "hashmap.h"
|
2015-10-26 23:32:16 +01:00
|
|
|
#include "journal-file.h"
|
2012-08-22 03:43:45 +02:00
|
|
|
#include "journald-rate-limit.h"
|
2015-11-01 21:50:24 +01:00
|
|
|
#include "journald-stream.h"
|
2012-01-04 20:40:04 +01:00
|
|
|
#include "list.h"
|
|
|
|
|
2012-07-01 20:17:48 +02:00
|
|
|
typedef enum Storage {
|
|
|
|
STORAGE_AUTO,
|
|
|
|
STORAGE_VOLATILE,
|
2012-07-10 19:39:27 +02:00
|
|
|
STORAGE_PERSISTENT,
|
2012-07-01 20:17:48 +02:00
|
|
|
STORAGE_NONE,
|
|
|
|
_STORAGE_MAX,
|
|
|
|
_STORAGE_INVALID = -1
|
|
|
|
} Storage;
|
|
|
|
|
2012-09-07 23:40:00 +02:00
|
|
|
typedef enum SplitMode {
|
|
|
|
SPLIT_UID,
|
2016-07-26 08:19:33 +02:00
|
|
|
SPLIT_LOGIN, /* deprecated */
|
2012-09-07 23:40:00 +02:00
|
|
|
SPLIT_NONE,
|
|
|
|
_SPLIT_MAX,
|
|
|
|
_SPLIT_INVALID = -1
|
|
|
|
} SplitMode;
|
|
|
|
|
2015-11-01 21:50:24 +01:00
|
|
|
struct Server {
|
2012-01-04 20:40:04 +01:00
|
|
|
int syslog_fd;
|
|
|
|
int native_fd;
|
|
|
|
int stdout_fd;
|
2012-08-09 15:57:24 +02:00
|
|
|
int dev_kmsg_fd;
|
2014-11-03 20:58:24 +01:00
|
|
|
int audit_fd;
|
2013-12-11 22:55:57 +01:00
|
|
|
int hostname_fd;
|
2015-11-01 21:50:24 +01:00
|
|
|
int notify_fd;
|
2012-01-04 20:40:04 +01:00
|
|
|
|
2013-12-11 20:13:44 +01:00
|
|
|
sd_event *event;
|
|
|
|
|
|
|
|
sd_event_source *syslog_event_source;
|
|
|
|
sd_event_source *native_event_source;
|
|
|
|
sd_event_source *stdout_event_source;
|
|
|
|
sd_event_source *dev_kmsg_event_source;
|
2014-11-03 20:58:24 +01:00
|
|
|
sd_event_source *audit_event_source;
|
2013-12-11 20:13:44 +01:00
|
|
|
sd_event_source *sync_event_source;
|
|
|
|
sd_event_source *sigusr1_event_source;
|
|
|
|
sd_event_source *sigusr2_event_source;
|
|
|
|
sd_event_source *sigterm_event_source;
|
|
|
|
sd_event_source *sigint_event_source;
|
2015-11-11 12:59:09 +01:00
|
|
|
sd_event_source *sigrtmin1_event_source;
|
2013-12-11 22:55:57 +01:00
|
|
|
sd_event_source *hostname_event_source;
|
2015-11-01 21:50:24 +01:00
|
|
|
sd_event_source *notify_event_source;
|
2015-11-03 12:28:19 +01:00
|
|
|
sd_event_source *watchdog_event_source;
|
2013-12-11 20:13:44 +01:00
|
|
|
|
2012-01-04 20:40:04 +01:00
|
|
|
JournalFile *runtime_journal;
|
|
|
|
JournalFile *system_journal;
|
2014-08-22 13:44:14 +02:00
|
|
|
OrderedHashmap *user_journals;
|
2012-01-04 20:40:04 +01:00
|
|
|
|
|
|
|
uint64_t seqnum;
|
|
|
|
|
|
|
|
char *buffer;
|
|
|
|
size_t buffer_size;
|
|
|
|
|
|
|
|
JournalRateLimit *rate_limit;
|
2013-03-25 17:49:03 +01:00
|
|
|
usec_t sync_interval_usec;
|
2012-01-04 20:40:04 +01:00
|
|
|
usec_t rate_limit_interval;
|
|
|
|
unsigned rate_limit_burst;
|
|
|
|
|
|
|
|
JournalMetrics runtime_metrics;
|
|
|
|
JournalMetrics system_metrics;
|
|
|
|
|
|
|
|
bool compress;
|
2012-08-20 22:13:22 +02:00
|
|
|
bool seal;
|
2012-01-04 20:40:04 +01:00
|
|
|
|
2012-01-05 15:34:13 +01:00
|
|
|
bool forward_to_kmsg;
|
|
|
|
bool forward_to_syslog;
|
|
|
|
bool forward_to_console;
|
2014-03-14 00:38:15 +01:00
|
|
|
bool forward_to_wall;
|
2012-01-05 15:34:13 +01:00
|
|
|
|
2012-09-17 23:59:26 +02:00
|
|
|
unsigned n_forward_syslog_missed;
|
|
|
|
usec_t last_warn_forward_syslog_missed;
|
|
|
|
|
2015-10-02 23:21:59 +02:00
|
|
|
uint64_t cached_space_available;
|
|
|
|
uint64_t cached_space_limit;
|
|
|
|
usec_t cached_space_timestamp;
|
2012-01-04 20:40:04 +01:00
|
|
|
|
|
|
|
uint64_t var_available_timestamp;
|
|
|
|
|
2012-10-16 22:58:07 +02:00
|
|
|
usec_t max_retention_usec;
|
|
|
|
usec_t max_file_usec;
|
|
|
|
usec_t oldest_file_usec;
|
|
|
|
|
2012-01-04 20:40:04 +01:00
|
|
|
LIST_HEAD(StdoutStream, stdout_streams);
|
2015-11-01 21:50:24 +01:00
|
|
|
LIST_HEAD(StdoutStream, stdout_streams_notify_queue);
|
2012-01-04 20:40:04 +01:00
|
|
|
unsigned n_stdout_streams;
|
2012-06-01 01:06:10 +02:00
|
|
|
|
|
|
|
char *tty_path;
|
2012-06-01 17:26:16 +02:00
|
|
|
|
|
|
|
int max_level_store;
|
|
|
|
int max_level_syslog;
|
|
|
|
int max_level_kmsg;
|
|
|
|
int max_level_console;
|
2014-03-14 00:38:15 +01:00
|
|
|
int max_level_wall;
|
2012-07-01 20:17:48 +02:00
|
|
|
|
|
|
|
Storage storage;
|
2012-09-07 23:40:00 +02:00
|
|
|
SplitMode split_mode;
|
2012-08-09 15:57:24 +02:00
|
|
|
|
2012-08-14 22:02:24 +02:00
|
|
|
MMapCache *mmap;
|
|
|
|
|
2016-02-18 02:37:10 +01:00
|
|
|
Set *deferred_closes;
|
|
|
|
|
2015-11-03 12:28:19 +01:00
|
|
|
struct udev *udev;
|
2012-08-09 17:52:05 +02:00
|
|
|
|
|
|
|
uint64_t *kernel_seqnum;
|
2015-11-03 12:28:19 +01:00
|
|
|
bool dev_kmsg_readable:1;
|
2012-08-22 02:49:17 +02:00
|
|
|
|
2015-11-03 12:28:19 +01:00
|
|
|
bool send_watchdog:1;
|
|
|
|
bool sent_notify_ready:1;
|
|
|
|
bool sync_scheduled:1;
|
2013-12-11 22:55:57 +01:00
|
|
|
|
|
|
|
char machine_id_field[sizeof("_MACHINE_ID=") + 32];
|
|
|
|
char boot_id_field[sizeof("_BOOT_ID=") + 32];
|
|
|
|
char *hostname_field;
|
2013-12-11 23:31:07 +01:00
|
|
|
|
|
|
|
/* Cached cgroup root, so that we don't have to query that all the time */
|
|
|
|
char *cgroup_root;
|
2015-11-03 12:28:19 +01:00
|
|
|
|
|
|
|
usec_t watchdog_usec;
|
2015-11-01 21:50:24 +01:00
|
|
|
};
|
2012-01-04 20:40:04 +01:00
|
|
|
|
2015-10-02 23:21:59 +02:00
|
|
|
#define SERVER_MACHINE_ID(s) ((s)->machine_id_field + strlen("_MACHINE_ID="))
|
|
|
|
|
2016-08-30 23:18:46 +02:00
|
|
|
#define N_IOVEC_META_FIELDS 22
|
2012-08-22 03:09:44 +02:00
|
|
|
#define N_IOVEC_KERNEL_FIELDS 64
|
|
|
|
#define N_IOVEC_UDEV_FIELDS 32
|
2016-08-30 21:00:52 +02:00
|
|
|
#define N_IOVEC_OBJECT_FIELDS 14
|
journald: use structured message + catalog entry for disk usage
The format of the journald disk usage log entry was changed back and
forth a few times. It is annoying to have a very verbose message, but
if it is short it is hard to understand. But we have a tool for this,
the catalogue.
$ journalctl -x -u systemd-journald
Jan 23 18:48:50 rawhide systemd-journald[891]: Runtime journal (/run/log/journal/) is 8.0M, max 196.2M, 188.2M free.
-- Subject: Disk space used by the journal
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Runtime journal (/run/log/journal/) is currently using 8.0M.
-- Maximum allowed usage is set to 196.2M.
-- Leaving at least 294.3M free (of currently available 1.9G of disk space).
-- Enforced usage limit is thus 196.2M, of which 188.2M are still available.
--
-- The limits controlling how much disk space is used by the journal may
-- be configured with SystemMaxUse=, SystemKeepFree=, SystemMaxFileSize=,
-- RuntimeMaxUse=, RuntimeKeepFree=, RuntimeMaxFileSize= settings in
-- /etc/systemd/journald.conf. See journald.conf(5) for details.
Jan 23 18:48:50 rawhide systemd-journald[891]: System journal (/var/log/journal/) is 480.1M, max 1.6G, 1.2G free.
-- Subject: Disk space used by the journal
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- System journal (/var/log/journal/) is currently using 480.1M.
-- Maximum allowed usage is set to 1.6G.
-- Leaving at least 2.5G free (of currently available 5.8G of disk space).
-- Enforced usage limit is thus 1.6G, of which 1.2G are still available.
--
-- The limits controlling how much disk space is used by the journal may
-- be configured with SystemMaxUse=, SystemKeepFree=, SystemMaxFileSize=,
-- RuntimeMaxUse=, RuntimeKeepFree=, RuntimeMaxFileSize= settings in
-- /etc/systemd/journald.conf. See journald.conf(5) for details.
2015-11-10 13:44:19 +01:00
|
|
|
#define N_IOVEC_PAYLOAD_FIELDS 15
|
2012-08-22 03:09:44 +02:00
|
|
|
|
2014-11-02 21:46:42 +01:00
|
|
|
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);
|
2015-11-08 20:05:55 +01:00
|
|
|
void server_driver_message(Server *s, sd_id128_t message_id, const char *format, ...) _printf_(3,0) _sentinel_;
|
2012-08-22 03:09:44 +02:00
|
|
|
|
2012-01-04 20:40:04 +01:00
|
|
|
/* gperf lookup function */
|
|
|
|
const struct ConfigPerfItem* journald_gperf_lookup(const char *key, unsigned length);
|
|
|
|
|
2013-11-19 16:17:55 +01:00
|
|
|
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);
|
2012-07-01 20:17:48 +02:00
|
|
|
|
2013-05-03 04:51:50 +02:00
|
|
|
const char *storage_to_string(Storage s) _const_;
|
|
|
|
Storage storage_from_string(const char *s) _pure_;
|
2012-09-07 23:40:00 +02:00
|
|
|
|
2013-11-19 16:17:55 +01:00
|
|
|
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);
|
2012-09-07 23:40:00 +02:00
|
|
|
|
2013-05-03 04:51:50 +02:00
|
|
|
const char *split_mode_to_string(SplitMode s) _const_;
|
|
|
|
SplitMode split_mode_from_string(const char *s) _pure_;
|
2012-11-12 17:29:07 +01:00
|
|
|
|
|
|
|
int server_init(Server *s);
|
|
|
|
void server_done(Server *s);
|
2013-03-25 17:49:03 +01:00
|
|
|
void server_sync(Server *s);
|
2015-10-02 23:21:59 +02:00
|
|
|
int server_vacuum(Server *s, bool verbose, bool patch_min_use);
|
2012-11-12 17:29:07 +01:00
|
|
|
void server_rotate(Server *s);
|
2013-07-24 08:08:57 +02:00
|
|
|
int server_schedule_sync(Server *s, int priority);
|
2012-11-12 17:29:07 +01:00
|
|
|
int server_flush_to_var(Server *s);
|
|
|
|
void server_maybe_append_tags(Server *s);
|
2015-01-04 22:09:07 +01:00
|
|
|
int server_process_datagram(sd_event_source *es, int fd, uint32_t revents, void *userdata);
|