chiark / gitweb /
journald: parse configuration file
authorLennart Poettering <lennart@poettering.net>
Wed, 4 Jan 2012 19:40:04 +0000 (20:40 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 4 Jan 2012 19:40:04 +0000 (20:40 +0100)
Makefile.am
src/conf-parser.c
src/conf-parser.h
src/journal/.gitignore
src/journal/journald-gperf.gperf [new file with mode: 0644]
src/journal/journald.c
src/journal/journald.h [new file with mode: 0644]
src/journal/systemd-journald.conf [new file with mode: 0644]
src/login/logind.c

index fe54eadf356bd8faf9b812b377c86413ef81a02d..09df759d0e5d0997d51ef79041fb5560d2352c7e 100644 (file)
@@ -1171,6 +1171,9 @@ systemd_journald_SOURCES = \
        src/acl-util.c \
        src/cgroup-util.c
 
        src/acl-util.c \
        src/cgroup-util.c
 
+nodist_systemd_journald_SOURCES = \
+        src/journal/journald-gperf.c
+
 systemd_journald_CFLAGS = \
        $(AM_CFLAGS) \
        $(ACL_CFLAGS)
 systemd_journald_CFLAGS = \
        $(AM_CFLAGS) \
        $(ACL_CFLAGS)
@@ -1302,6 +1305,9 @@ dist_systemunit_DATA += \
 nodist_systemunit_DATA += \
        units/systemd-journald.service
 
 nodist_systemunit_DATA += \
        units/systemd-journald.service
 
+dist_pkgsysconf_DATA += \
+       src/journal/systemd-journald.conf
+
 pkgconfiglib_DATA += \
        src/journal/libsystemd-journal.pc
 
 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 \
        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
 
 # ------------------------------------------------------------------------------
 if ENABLE_BINFMT
index a71dcd0d8fb8c87460ea24f81b244334ce740519..b60f93d7a45570e01d5f4449edde5ca369e92da3 100644 (file)
@@ -752,3 +752,30 @@ int config_parse_mode(
         *m = (mode_t) l;
         return 0;
 }
         *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;
+}
index cbb4235d69ed12bc4a535b9fedcc527c40836ee8..e970ee28345c5df466e65a29faa5e6423b360737 100644 (file)
@@ -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_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(                                                   \
 
 #define DEFINE_CONFIG_PARSE_ENUM(function,name,type,msg)                \
         int function(                                                   \
index faf48e7dc35a055d74f462050f024a7ac9567c41..d6a79460cdbccd48249db68754f7c04f314be0f7 100644 (file)
@@ -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 (file)
index 0000000..ace373b
--- /dev/null
@@ -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)
index b029ab97814d1845ff5cf18c454e8b453dc55243..68c1c23cdf23869df80a0f5bb1d81f07e4a0c252 100644 (file)
@@ -43,6 +43,8 @@
 #include "sd-journal.h"
 #include "sd-login.h"
 #include "journal-internal.h"
 #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
 
 #define USER_JOURNALS_MAX 1024
 #define STDOUT_STREAMS_MAX 4096
 
 #define SYSLOG_TIMEOUT_USEC (5*USEC_PER_SEC)
 
 
 #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,
 typedef enum StdoutStreamState {
         STDOUT_STREAM_TAG,
         STDOUT_STREAM_PRIORITY,
@@ -1761,6 +1729,32 @@ static int open_signalfd(Server *s) {
         return 0;
 }
 
         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;
 
 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->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));
 
         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.");
         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;
 
         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;
 
         if (!s->rate_limit)
                 return -ENOMEM;
 
@@ -1916,15 +1915,15 @@ int main(int argc, char *argv[]) {
         if (r < 0)
                 goto finish;
 
         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...");
 
         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;
 
         for (;;) {
                 struct epoll_event event;
 
diff --git a/src/journal/journald.h b/src/journal/journald.h
new file mode 100644 (file)
index 0000000..47feca4
--- /dev/null
@@ -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 (file)
index 0000000..f137ab8
--- /dev/null
@@ -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=
index 333d5f85bdd09c808c310bc7d513a2c3cd864f58..0df6b8964c887ecc59225d7524d6af97d04a4add 100644 (file)
@@ -1224,9 +1224,20 @@ int main(int argc, char *argv[]) {
                 goto finish;
         }
 
                 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);
 
         r = manager_run(m);
 
+        log_debug("systemd-logind stopped as pid %lu", (unsigned long) getpid());
+
 finish:
 finish:
+        sd_notify(false,
+                  "STATUS=Shutting down...");
+
         if (m)
                 manager_free(m);
 
         if (m)
                 manager_free(m);