diff options
-rw-r--r-- | Makefile.am | 12 | ||||
-rw-r--r-- | src/conf-parser.c | 27 | ||||
-rw-r--r-- | src/conf-parser.h | 1 | ||||
-rw-r--r-- | src/journal/.gitignore | 3 | ||||
-rw-r--r-- | src/journal/journald-gperf.gperf | 27 | ||||
-rw-r--r-- | src/journal/journald.c | 75 | ||||
-rw-r--r-- | src/journal/journald.h | 74 | ||||
-rw-r--r-- | src/journal/systemd-journald.conf | 21 | ||||
-rw-r--r-- | src/login/logind.c | 11 |
9 files changed, 211 insertions, 40 deletions
diff --git a/Makefile.am b/Makefile.am index fe54eadf35..09df759d0e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1171,6 +1171,9 @@ systemd_journald_SOURCES = \ src/acl-util.c \ src/cgroup-util.c +nodist_systemd_journald_SOURCES = \ + src/journal/journald-gperf.c + systemd_journald_CFLAGS = \ $(AM_CFLAGS) \ $(ACL_CFLAGS) @@ -1302,6 +1305,9 @@ dist_systemunit_DATA += \ nodist_systemunit_DATA += \ units/systemd-journald.service +dist_pkgsysconf_DATA += \ + src/journal/systemd-journald.conf + pkgconfiglib_DATA += \ src/journal/libsystemd-journal.pc @@ -1324,7 +1330,11 @@ EXTRA_DIST += \ src/journal/journal-rate-limit.h \ src/journal/libsystemd-journal.pc.in \ src/journal/libsystemd-journal.sym \ - units/systemd-journald.service.in + units/systemd-journald.service.in \ + src/journal/journald-gperf.gperf + +CLEANFILES += \ + src/journal/journald-gperf.c # ------------------------------------------------------------------------------ if ENABLE_BINFMT diff --git a/src/conf-parser.c b/src/conf-parser.c index a71dcd0d8f..b60f93d7a4 100644 --- a/src/conf-parser.c +++ b/src/conf-parser.c @@ -752,3 +752,30 @@ int config_parse_mode( *m = (mode_t) l; return 0; } + +int config_parse_bytes( + const char *filename, + unsigned line, + const char *section, + const char *lvalue, + int ltype, + const char *rvalue, + void *data, + void *userdata) { + + uint64_t *bytes = data; + + assert(filename); + assert(lvalue); + assert(rvalue); + assert(data); + + assert_cc(sizeof(off_t) == sizeof(uint64_t)); + + if (parse_bytes(rvalue, bytes) < 0) { + log_error("[%s:%u] Failed to parse bytes value, ignoring: %s", filename, line, rvalue); + return 0; + } + + return 0; +} diff --git a/src/conf-parser.h b/src/conf-parser.h index cbb4235d69..e970ee2834 100644 --- a/src/conf-parser.h +++ b/src/conf-parser.h @@ -101,6 +101,7 @@ int config_parse_strv(const char *filename, unsigned line, const char *section, int config_parse_path_strv(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); int config_parse_usec(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); int config_parse_mode(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); +int config_parse_bytes(const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); #define DEFINE_CONFIG_PARSE_ENUM(function,name,type,msg) \ int function( \ diff --git a/src/journal/.gitignore b/src/journal/.gitignore index faf48e7dc3..d6a79460cd 100644 --- a/src/journal/.gitignore +++ b/src/journal/.gitignore @@ -1 +1,2 @@ -libsystemd-journal.pc +/journald-gperf.c +/libsystemd-journal.pc diff --git a/src/journal/journald-gperf.gperf b/src/journal/journald-gperf.gperf new file mode 100644 index 0000000000..ace373ba47 --- /dev/null +++ b/src/journal/journald-gperf.gperf @@ -0,0 +1,27 @@ +%{ +#include <stddef.h> +#include "conf-parser.h" +#include "journald.h" +%} +struct ConfigPerfItem; +%null_strings +%language=ANSI-C +%define slot-name section_and_lvalue +%define hash-function-name journald_gperf_hash +%define lookup-function-name journald_gperf_lookup +%readonly-tables +%omit-struct-type +%struct-type +%includes +%% +Journal.RateLimitInterval, config_parse_usec, 0, offsetof(Server, rate_limit_interval) +Journal.RateLimitBurst, config_parse_unsigned, 0, offsetof(Server, rate_limit_burst) +Journal.Compress, config_parse_bool, 0, offsetof(Server, compress) +Journal.SystemMaxUse, config_parse_bytes, 0, offsetof(Server, system_metrics.max_use) +Journal.SystemMaxFileSize, config_parse_bytes, 0, offsetof(Server, system_metrics.max_size) +Journal.SystemMinFileSize, config_parse_bytes, 0, offsetof(Server, system_metrics.min_size) +Journal.SystemKeepFree, config_parse_bytes, 0, offsetof(Server, system_metrics.keep_free) +Journal.RuntimeMaxUse, config_parse_bytes, 0, offsetof(Server, runtime_metrics.max_use) +Journal.RuntimeMaxFileSize, config_parse_bytes, 0, offsetof(Server, runtime_metrics.max_size) +Journal.RuntimeMinFileSize, config_parse_bytes, 0, offsetof(Server, runtime_metrics.min_size) +Journal.RuntimeKeepFree, config_parse_bytes, 0, offsetof(Server, runtime_metrics.keep_free) diff --git a/src/journal/journald.c b/src/journal/journald.c index b029ab9781..68c1c23cdf 100644 --- a/src/journal/journald.c +++ b/src/journal/journald.c @@ -43,6 +43,8 @@ #include "sd-journal.h" #include "sd-login.h" #include "journal-internal.h" +#include "conf-parser.h" +#include "journald.h" #define USER_JOURNALS_MAX 1024 #define STDOUT_STREAMS_MAX 4096 @@ -56,40 +58,6 @@ #define SYSLOG_TIMEOUT_USEC (5*USEC_PER_SEC) -typedef struct StdoutStream StdoutStream; - -typedef struct Server { - int epoll_fd; - int signal_fd; - int syslog_fd; - int native_fd; - int stdout_fd; - - JournalFile *runtime_journal; - JournalFile *system_journal; - Hashmap *user_journals; - - uint64_t seqnum; - - char *buffer; - size_t buffer_size; - - JournalRateLimit *rate_limit; - - JournalMetrics runtime_metrics; - JournalMetrics system_metrics; - - bool compress; - - uint64_t cached_available_space; - usec_t cached_available_space_timestamp; - - uint64_t var_available_timestamp; - - LIST_HEAD(StdoutStream, stdout_streams); - unsigned n_stdout_streams; -} Server; - typedef enum StdoutStreamState { STDOUT_STREAM_TAG, STDOUT_STREAM_PRIORITY, @@ -1761,6 +1729,32 @@ static int open_signalfd(Server *s) { return 0; } +static int server_parse_config_file(Server *s) { + FILE *f; + const char *fn; + int r; + + assert(s); + + fn = "/etc/systemd/systemd-journald.conf"; + f = fopen(fn, "re"); + if (!f) { + if (errno == ENOENT) + return 0; + + log_warning("Failed to open configuration file %s: %m", fn); + return -errno; + } + + r = config_parse(fn, f, "Journal\0", config_item_perf_lookup, (void*) journald_gperf_lookup, false, s); + if (r < 0) + log_warning("Failed to parse configuration file: %s", strerror(-r)); + + fclose(f); + + return r; +} + static int server_init(Server *s) { int n, r, fd; @@ -1770,9 +1764,14 @@ static int server_init(Server *s) { s->syslog_fd = s->native_fd = s->stdout_fd = s->signal_fd = s->epoll_fd = -1; s->compress = true; + s->rate_limit_interval = DEFAULT_RATE_LIMIT_INTERVAL; + s->rate_limit_burst = DEFAULT_RATE_LIMIT_BURST; + memset(&s->system_metrics, 0xFF, sizeof(s->system_metrics)); memset(&s->runtime_metrics, 0xFF, sizeof(s->runtime_metrics)); + server_parse_config_file(s); + s->user_journals = hashmap_new(trivial_hash_func, trivial_compare_func); if (!s->user_journals) { log_error("Out of memory."); @@ -1846,7 +1845,7 @@ static int server_init(Server *s) { if (r < 0) return r; - s->rate_limit = journal_rate_limit_new(DEFAULT_RATE_LIMIT_INTERVAL, DEFAULT_RATE_LIMIT_BURST); + s->rate_limit = journal_rate_limit_new(s->rate_limit_interval, s->rate_limit_burst); if (!s->rate_limit) return -ENOMEM; @@ -1916,15 +1915,15 @@ int main(int argc, char *argv[]) { if (r < 0) goto finish; + server_vacuum(&server); + server_flush_to_var(&server); + log_debug("systemd-journald running as pid %lu", (unsigned long) getpid()); sd_notify(false, "READY=1\n" "STATUS=Processing requests..."); - server_vacuum(&server); - server_flush_to_var(&server); - for (;;) { struct epoll_event event; diff --git a/src/journal/journald.h b/src/journal/journald.h new file mode 100644 index 0000000000..47feca40aa --- /dev/null +++ b/src/journal/journald.h @@ -0,0 +1,74 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +#ifndef foojournaldhfoo +#define foojournaldhfoo + +/*** + This file is part of systemd. + + Copyright 2011 Lennart Poettering + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with systemd; If not, see <http://www.gnu.org/licenses/>. +***/ + +#include <inttypes.h> +#include <sys/types.h> +#include <stdbool.h> + +#include "journal-file.h" +#include "hashmap.h" +#include "util.h" +#include "journal-rate-limit.h" +#include "list.h" + +typedef struct StdoutStream StdoutStream; + +typedef struct Server { + int epoll_fd; + int signal_fd; + int syslog_fd; + int native_fd; + int stdout_fd; + + JournalFile *runtime_journal; + JournalFile *system_journal; + Hashmap *user_journals; + + uint64_t seqnum; + + char *buffer; + size_t buffer_size; + + JournalRateLimit *rate_limit; + usec_t rate_limit_interval; + unsigned rate_limit_burst; + + JournalMetrics runtime_metrics; + JournalMetrics system_metrics; + + bool compress; + + uint64_t cached_available_space; + usec_t cached_available_space_timestamp; + + uint64_t var_available_timestamp; + + LIST_HEAD(StdoutStream, stdout_streams); + unsigned n_stdout_streams; +} Server; + +/* gperf lookup function */ +const struct ConfigPerfItem* journald_gperf_lookup(const char *key, unsigned length); + +#endif diff --git a/src/journal/systemd-journald.conf b/src/journal/systemd-journald.conf new file mode 100644 index 0000000000..f137ab8833 --- /dev/null +++ b/src/journal/systemd-journald.conf @@ -0,0 +1,21 @@ +# This file is part of systemd. +# +# systemd is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# See system-journald.conf(5) for details + +[Journal] +#Compress=yes +#RateLimitInterval=10s +#RateLimitBurst=200 +#SystemMaxUse= +#SystemKeepFree= +#SystemMaxFileSize= +#SystemMinFileSize= +#RuntimeMaxUse= +#RuntimeKeepFree= +#RuntimeMaxFileSize= +#RuntimeMinFileSize= diff --git a/src/login/logind.c b/src/login/logind.c index 333d5f85bd..0df6b8964c 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -1224,9 +1224,20 @@ int main(int argc, char *argv[]) { goto finish; } + log_debug("systemd-logind running as pid %lu", (unsigned long) getpid()); + + sd_notify(false, + "READY=1\n" + "STATUS=Processing requests..."); + r = manager_run(m); + log_debug("systemd-logind stopped as pid %lu", (unsigned long) getpid()); + finish: + sd_notify(false, + "STATUS=Shutting down..."); + if (m) manager_free(m); |