journald-server.h revision 119e9655dc36f18ed74f9a256d5c693b5aeb43ab
c2756a68401102786be343712c0c35acbd73d28dLennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
c2756a68401102786be343712c0c35acbd73d28dLennart Poettering
c2756a68401102786be343712c0c35acbd73d28dLennart Poettering#pragma once
c2756a68401102786be343712c0c35acbd73d28dLennart Poettering
c2756a68401102786be343712c0c35acbd73d28dLennart Poettering/***
c2756a68401102786be343712c0c35acbd73d28dLennart Poettering This file is part of systemd.
c2756a68401102786be343712c0c35acbd73d28dLennart Poettering
c2756a68401102786be343712c0c35acbd73d28dLennart Poettering Copyright 2011 Lennart Poettering
c2756a68401102786be343712c0c35acbd73d28dLennart Poettering
c2756a68401102786be343712c0c35acbd73d28dLennart Poettering systemd is free software; you can redistribute it and/or modify it
c2756a68401102786be343712c0c35acbd73d28dLennart Poettering under the terms of the GNU Lesser General Public License as published by
c2756a68401102786be343712c0c35acbd73d28dLennart Poettering the Free Software Foundation; either version 2.1 of the License, or
c2756a68401102786be343712c0c35acbd73d28dLennart Poettering (at your option) any later version.
c2756a68401102786be343712c0c35acbd73d28dLennart Poettering
c2756a68401102786be343712c0c35acbd73d28dLennart Poettering systemd is distributed in the hope that it will be useful, but
c2756a68401102786be343712c0c35acbd73d28dLennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
c2756a68401102786be343712c0c35acbd73d28dLennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
c2756a68401102786be343712c0c35acbd73d28dLennart Poettering Lesser General Public License for more details.
c2756a68401102786be343712c0c35acbd73d28dLennart Poettering
c2756a68401102786be343712c0c35acbd73d28dLennart Poettering You should have received a copy of the GNU Lesser General Public License
c2756a68401102786be343712c0c35acbd73d28dLennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
c2756a68401102786be343712c0c35acbd73d28dLennart Poettering***/
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering
c2756a68401102786be343712c0c35acbd73d28dLennart Poettering#include <stdbool.h>
c2756a68401102786be343712c0c35acbd73d28dLennart Poettering#include <sys/types.h>
9b15b7846d4de01bb5d9700a24077787e984e8abLennart Poettering
40ca29a1370379d43e44c0ed425eecc7218dcbcaLennart Poettering#include "sd-event.h"
9b15b7846d4de01bb5d9700a24077787e984e8abLennart Poettering
c2756a68401102786be343712c0c35acbd73d28dLennart Poetteringtypedef struct Server Server;
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering#include "hashmap.h"
4de33e7f3238a6fe616e61139ab87e221572e5e5Lennart Poettering#include "journal-file.h"
4bcc8c3cb57733de6eeb2528a194501fade11e6bZbigniew Jędrzejewski-Szmek#include "journald-rate-limit.h"
94676f3e9352cbf1f72e0a512ee0d2ed83ff676dLennart Poettering#include "journald-stream.h"
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho#include "list.h"
9b15b7846d4de01bb5d9700a24077787e984e8abLennart Poettering
c2756a68401102786be343712c0c35acbd73d28dLennart Poetteringtypedef enum Storage {
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering STORAGE_AUTO,
6577c7cea72f19185ad999c223bcf663c010dc6fLennart Poettering STORAGE_VOLATILE,
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering STORAGE_PERSISTENT,
9f2e86af0600e99cff00d1c92f9bb8d38f29896aLennart Poettering STORAGE_NONE,
c221420be8744bb0f8b8a8145efc1f247f1aa801Lennart Poettering _STORAGE_MAX,
a6c0353b9268d5b780fb7ff05a10cb5031446e5dLennart Poettering _STORAGE_INVALID = -1
d21ed1ead18d16d35c30299a69d3366847f8a039Lennart Poettering} Storage;
1ac67edb7c4d31a287fa98c0b554ae98bd34e71bLennart Poettering
d21ed1ead18d16d35c30299a69d3366847f8a039Lennart Poetteringtypedef enum SplitMode {
c7040b5d1c2c148f12b6a5eef3dfce1661805131Lennart Poettering SPLIT_UID,
c7040b5d1c2c148f12b6a5eef3dfce1661805131Lennart Poettering SPLIT_LOGIN,
c7040b5d1c2c148f12b6a5eef3dfce1661805131Lennart Poettering SPLIT_NONE,
c7040b5d1c2c148f12b6a5eef3dfce1661805131Lennart Poettering _SPLIT_MAX,
c7040b5d1c2c148f12b6a5eef3dfce1661805131Lennart Poettering _SPLIT_INVALID = -1
c7040b5d1c2c148f12b6a5eef3dfce1661805131Lennart Poettering} SplitMode;
df31a6c0fe07805cb50045fbe91c2a6e7e430562Lennart Poettering
9b15b7846d4de01bb5d9700a24077787e984e8abLennart Poetteringstruct Server {
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho int syslog_fd;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho int native_fd;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho int stdout_fd;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho int dev_kmsg_fd;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho int audit_fd;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho int hostname_fd;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho int notify_fd;
095dc59660c3dde782f32fe5a52b577f7700578bLennart Poettering
c2756a68401102786be343712c0c35acbd73d28dLennart Poettering sd_event *event;
601185b43da638b1c74153deae01dbd518680889Zbigniew Jędrzejewski-Szmek
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho sd_event_source *syslog_event_source;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho sd_event_source *native_event_source;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho sd_event_source *stdout_event_source;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho sd_event_source *dev_kmsg_event_source;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho sd_event_source *audit_event_source;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho sd_event_source *sync_event_source;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho sd_event_source *sigusr1_event_source;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho sd_event_source *sigusr2_event_source;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho sd_event_source *sigterm_event_source;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho sd_event_source *sigint_event_source;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho sd_event_source *hostname_event_source;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho sd_event_source *notify_event_source;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho sd_event_source *watchdog_event_source;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho JournalFile *runtime_journal;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho JournalFile *system_journal;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho OrderedHashmap *user_journals;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho uint64_t seqnum;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho
9b15b7846d4de01bb5d9700a24077787e984e8abLennart Poettering char *buffer;
095dc59660c3dde782f32fe5a52b577f7700578bLennart Poettering size_t buffer_size;
095dc59660c3dde782f32fe5a52b577f7700578bLennart Poettering
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho JournalRateLimit *rate_limit;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho usec_t sync_interval_usec;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho usec_t rate_limit_interval;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho unsigned rate_limit_burst;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho JournalMetrics runtime_metrics;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho JournalMetrics system_metrics;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering bool compress;
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering bool seal;
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho bool forward_to_kmsg;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho bool forward_to_syslog;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho bool forward_to_console;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho bool forward_to_wall;
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering unsigned n_forward_syslog_missed;
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering usec_t last_warn_forward_syslog_missed;
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering uint64_t cached_space_available;
66b1e746055b9c56fd72c0451a4cfb2b06cf3f20Lennart Poettering uint64_t cached_space_limit;
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering usec_t cached_space_timestamp;
9f2e86af0600e99cff00d1c92f9bb8d38f29896aLennart Poettering
c221420be8744bb0f8b8a8145efc1f247f1aa801Lennart Poettering uint64_t var_available_timestamp;
a6c0353b9268d5b780fb7ff05a10cb5031446e5dLennart Poettering
a6c0353b9268d5b780fb7ff05a10cb5031446e5dLennart Poettering usec_t max_retention_usec;
c7040b5d1c2c148f12b6a5eef3dfce1661805131Lennart Poettering usec_t max_file_usec;
c7040b5d1c2c148f12b6a5eef3dfce1661805131Lennart Poettering usec_t oldest_file_usec;
c7040b5d1c2c148f12b6a5eef3dfce1661805131Lennart Poettering
c7040b5d1c2c148f12b6a5eef3dfce1661805131Lennart Poettering LIST_HEAD(StdoutStream, stdout_streams);
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho LIST_HEAD(StdoutStream, stdout_streams_notify_queue);
9b15b7846d4de01bb5d9700a24077787e984e8abLennart Poettering unsigned n_stdout_streams;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho char *tty_path;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho int max_level_store;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho int max_level_syslog;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho int max_level_kmsg;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho int max_level_console;
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering int max_level_wall;
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering Storage storage;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho SplitMode split_mode;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho MMapCache *mmap;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho struct udev *udev;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho uint64_t *kernel_seqnum;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho bool dev_kmsg_readable:1;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho bool send_watchdog:1;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho bool sent_notify_ready:1;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho bool sync_scheduled:1;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho char machine_id_field[sizeof("_MACHINE_ID=") + 32];
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho char boot_id_field[sizeof("_BOOT_ID=") + 32];
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho char *hostname_field;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho /* Cached cgroup root, so that we don't have to query that all the time */
9b15b7846d4de01bb5d9700a24077787e984e8abLennart Poettering char *cgroup_root;
095dc59660c3dde782f32fe5a52b577f7700578bLennart Poettering
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho usec_t watchdog_usec;
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho};
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho#define SERVER_MACHINE_ID(s) ((s)->machine_id_field + strlen("_MACHINE_ID="))
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho#define N_IOVEC_META_FIELDS 20
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Cho#define N_IOVEC_KERNEL_FIELDS 64
eb9da376d76b48585b3b63b4f91903b54f7abd36Lennart Poettering#define N_IOVEC_UDEV_FIELDS 32
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering#define N_IOVEC_OBJECT_FIELDS 12
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering
c7040b5d1c2c148f12b6a5eef3dfce1661805131Lennart Poetteringvoid 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);
4c213d6cf416917c61f82d8bee795b8f3a4c5372WaLyong Chovoid server_driver_message(Server *s, sd_id128_t message_id, const char *format, ...) _printf_(3,4);
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering/* gperf lookup function */
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poetteringconst struct ConfigPerfItem* journald_gperf_lookup(const char *key, unsigned length);
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering
095dc59660c3dde782f32fe5a52b577f7700578bLennart Poetteringint 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);
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poetteringconst char *storage_to_string(Storage s) _const_;
6c12b52e19640747e96f89d85422941a23dc6b29Lennart PoetteringStorage storage_from_string(const char *s) _pure_;
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering
601185b43da638b1c74153deae01dbd518680889Zbigniew Jędrzejewski-Szmekint 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);
601185b43da638b1c74153deae01dbd518680889Zbigniew Jędrzejewski-Szmek
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poetteringconst char *split_mode_to_string(SplitMode s) _const_;
6c12b52e19640747e96f89d85422941a23dc6b29Lennart PoetteringSplitMode split_mode_from_string(const char *s) _pure_;
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poettering
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poetteringvoid server_fix_perms(Server *s, JournalFile *f, uid_t uid);
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poetteringint server_init(Server *s);
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poetteringvoid server_done(Server *s);
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poetteringvoid server_sync(Server *s);
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poetteringint server_vacuum(Server *s, bool verbose, bool patch_min_use);
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poetteringvoid server_rotate(Server *s);
6c12b52e19640747e96f89d85422941a23dc6b29Lennart Poetteringint server_schedule_sync(Server *s, int priority);
66b1e746055b9c56fd72c0451a4cfb2b06cf3f20Lennart Poetteringint server_flush_to_var(Server *s);
66b1e746055b9c56fd72c0451a4cfb2b06cf3f20Lennart Poetteringvoid server_maybe_append_tags(Server *s);
66b1e746055b9c56fd72c0451a4cfb2b06cf3f20Lennart Poetteringint server_process_datagram(sd_event_source *es, int fd, uint32_t revents, void *userdata);
66b1e746055b9c56fd72c0451a4cfb2b06cf3f20Lennart Poettering