diff options
author | Lennart Poettering <lennart@poettering.net> | 2010-07-07 01:10:27 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2010-07-07 01:10:27 +0200 |
commit | 487393e9f11e4a06d91df03232914bd8c4b3368e (patch) | |
tree | 137c84629b23a731a3cc114259204b296d7cb684 | |
parent | c846ff4798c4c48d229587297e6df8b593c60c54 (diff) |
main: implement manager configuration file
-rw-r--r-- | Makefile.am | 5 | ||||
-rw-r--r-- | src/conf-parser.h | 28 | ||||
-rw-r--r-- | src/load-fragment.c | 45 | ||||
-rw-r--r-- | src/main.c | 167 | ||||
-rw-r--r-- | src/system.conf | 19 |
5 files changed, 228 insertions, 36 deletions
diff --git a/Makefile.am b/Makefile.am index fd02db3d09..cdb5be314e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -38,10 +38,12 @@ systemunitdir=$(rootdir)/lib/systemd/system AM_CPPFLAGS = \ -include $(top_builddir)/config.h \ + -DSYSTEM_CONFIG_FILE=\"$(pkgsysconfdir)/system.conf\" \ -DSYSTEM_CONFIG_UNIT_PATH=\"$(pkgsysconfdir)/system\" \ -DSYSTEM_DATA_UNIT_PATH=\"$(systemunitdir)\" \ -DSYSTEM_SYSVINIT_PATH=\"$(SYSTEM_SYSVINIT_PATH)\" \ -DSYSTEM_SYSVRCND_PATH=\"$(SYSTEM_SYSVRCND_PATH)\" \ + -DSESSION_CONFIG_FILE=\"$(pkgsysconfdir)/session.conf\" \ -DSESSION_CONFIG_UNIT_PATH=\"$(pkgsysconfdir)/session\" \ -DSESSION_DATA_UNIT_PATH=\"$(sessionunitdir)\" \ -DCGROUP_AGENT_PATH=\"$(rootlibexecdir)/systemd-cgroups-agent\" \ @@ -81,6 +83,9 @@ pamlib_LTLIBRARIES = \ pam_systemd.la endif +dist_pkgsysconf_DATA = \ + src/system.conf + dist_dbuspolicy_DATA = \ src/org.freedesktop.systemd1.conf diff --git a/src/conf-parser.h b/src/conf-parser.h index b3b2915d41..2797076572 100644 --- a/src/conf-parser.h +++ b/src/conf-parser.h @@ -53,4 +53,32 @@ int config_parse_path(const char *filename, unsigned line, const char *section, int config_parse_strv(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata); int config_parse_path_strv(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata); +#define DEFINE_CONFIG_PARSE_ENUM(function,name,type,msg) \ + int function( \ + const char *filename, \ + unsigned line, \ + const char *section, \ + const char *lvalue, \ + const char *rvalue, \ + void *data, \ + void *userdata) { \ + \ + type *i = data, x; \ + \ + assert(filename); \ + assert(lvalue); \ + assert(rvalue); \ + assert(data); \ + \ + if ((x = name##_from_string(rvalue)) < 0) { \ + log_error("[%s:%u] " msg ": %s", filename, line, rvalue); \ + return -EBADMSG; \ + } \ + \ + *i = x; \ + \ + return 0; \ + } + + #endif diff --git a/src/load-fragment.c b/src/load-fragment.c index 3c0cccff49..591b73d01b 100644 --- a/src/load-fragment.c +++ b/src/load-fragment.c @@ -43,33 +43,6 @@ #define COMMENTS "#;\n" #define LINE_MAX 4096 -#define DEFINE_CONFIG_PARSE_ENUM(function,name,type,msg) \ - static int function( \ - const char *filename, \ - unsigned line, \ - const char *section, \ - const char *lvalue, \ - const char *rvalue, \ - void *data, \ - void *userdata) { \ - \ - type *i = data, x; \ - \ - assert(filename); \ - assert(lvalue); \ - assert(rvalue); \ - assert(data); \ - \ - if ((x = name##_from_string(rvalue)) < 0) { \ - log_error("[%s:%u] " msg ": %s", filename, line, rvalue); \ - return -EBADMSG; \ - } \ - \ - *i = x; \ - \ - return 0; \ - } - static int config_parse_deps( const char *filename, unsigned line, @@ -496,8 +469,8 @@ static int config_parse_usec( return 0; } -DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type, service_type, ServiceType, "Failed to parse service type"); -DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart, service_restart, ServiceRestart, "Failed to parse service restart specifier"); +static DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type, service_type, ServiceType, "Failed to parse service type"); +static DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart, service_restart, ServiceRestart, "Failed to parse service restart specifier"); static int config_parse_bindtodevice( const char *filename, @@ -528,8 +501,8 @@ static int config_parse_bindtodevice( return 0; } -DEFINE_CONFIG_PARSE_ENUM(config_parse_output, exec_output, ExecOutput, "Failed to parse output specifier"); -DEFINE_CONFIG_PARSE_ENUM(config_parse_input, exec_input, ExecInput, "Failed to parse input specifier"); +static DEFINE_CONFIG_PARSE_ENUM(config_parse_output, exec_output, ExecOutput, "Failed to parse output specifier"); +static DEFINE_CONFIG_PARSE_ENUM(config_parse_input, exec_input, ExecInput, "Failed to parse input specifier"); static int config_parse_facility( const char *filename, @@ -725,13 +698,13 @@ static int config_parse_cpu_affinity( if (!(t = strndup(w, l))) return -ENOMEM; + r = safe_atou(t, &cpu); + free(t); + if (!(c->cpuset)) if (!(c->cpuset = cpu_set_malloc(&c->cpuset_ncpus))) return -ENOMEM; - r = safe_atou(t, &cpu); - free(t); - if (r < 0 || cpu >= c->cpuset_ncpus) { log_error("[%s:%u] Failed to parse CPU affinity: %s", filename, line, rvalue); return -EBADMSG; @@ -973,7 +946,7 @@ static int config_parse_sysv_priority( return 0; } -DEFINE_CONFIG_PARSE_ENUM(config_parse_kill_mode, kill_mode, KillMode, "Failed to parse kill mode"); +static DEFINE_CONFIG_PARSE_ENUM(config_parse_kill_mode, kill_mode, KillMode, "Failed to parse kill mode"); static int config_parse_mount_flags( const char *filename, @@ -1234,7 +1207,7 @@ static int config_parse_ip_tos( return 0; } -DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access, notify_access, NotifyAccess, "Failed to parse notify access specifier"); +static DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access, notify_access, NotifyAccess, "Failed to parse notify access specifier"); #define FOLLOW_MAX 8 diff --git a/src/main.c b/src/main.c index df0da0be4f..a2dc1bc12f 100644 --- a/src/main.c +++ b/src/main.c @@ -42,6 +42,7 @@ #include "load-fragment.h" #include "fdset.h" #include "special.h" +#include "conf-parser.h" static enum { ACTION_RUN, @@ -338,6 +339,169 @@ static int parse_proc_cmdline_word(const char *word) { return 0; } +static int config_parse_level( + const char *filename, + unsigned line, + const char *section, + const char *lvalue, + const char *rvalue, + void *data, + void *userdata) { + + assert(filename); + assert(lvalue); + assert(rvalue); + + log_set_max_level_from_string(rvalue); + return 0; +} + +static int config_parse_target( + const char *filename, + unsigned line, + const char *section, + const char *lvalue, + const char *rvalue, + void *data, + void *userdata) { + + assert(filename); + assert(lvalue); + assert(rvalue); + + log_set_target_from_string(rvalue); + return 0; +} + +static int config_parse_color( + const char *filename, + unsigned line, + const char *section, + const char *lvalue, + const char *rvalue, + void *data, + void *userdata) { + + assert(filename); + assert(lvalue); + assert(rvalue); + + log_show_color_from_string(rvalue); + return 0; +} + +static int config_parse_location( + const char *filename, + unsigned line, + const char *section, + const char *lvalue, + const char *rvalue, + void *data, + void *userdata) { + + assert(filename); + assert(lvalue); + assert(rvalue); + + log_show_location_from_string(rvalue); + return 0; +} + +static int config_parse_cpu_affinity( + const char *filename, + unsigned line, + const char *section, + const char *lvalue, + const char *rvalue, + void *data, + void *userdata) { + + char *w; + size_t l; + char *state; + cpu_set_t *c = NULL; + unsigned ncpus = 0; + + assert(filename); + assert(lvalue); + assert(rvalue); + + FOREACH_WORD(w, l, rvalue, state) { + char *t; + int r; + unsigned cpu; + + if (!(t = strndup(w, l))) + return -ENOMEM; + + r = safe_atou(t, &cpu); + free(t); + + if (!c) + if (!(c = cpu_set_malloc(&ncpus))) + return -ENOMEM; + + if (r < 0 || cpu >= ncpus) { + log_error("[%s:%u] Failed to parse CPU affinity: %s", filename, line, rvalue); + CPU_FREE(c); + return -EBADMSG; + } + + CPU_SET_S(cpu, CPU_ALLOC_SIZE(ncpus), c); + } + + if (c) { + if (sched_setaffinity(0, CPU_ALLOC_SIZE(ncpus), c) < 0) + log_warning("Failed to set CPU affinity: %m"); + + CPU_FREE(c); + } + + return 0; +} + +static int parse_config_file(void) { + + const ConfigItem items[] = { + { "LogLevel", config_parse_level, NULL, "Manager" }, + { "LogTarget", config_parse_target, NULL, "Manager" }, + { "LogColor", config_parse_color, NULL, "Manager" }, + { "LogLocation", config_parse_location, NULL, "Manager" }, + { "DumpCore", config_parse_bool, &arg_dump_core, "Manager" }, + { "CrashShell", config_parse_bool, &arg_crash_shell, "Manager" }, + { "ShowStatus", config_parse_bool, &arg_show_status, "Manager" }, + { "CrashChVT", config_parse_int, &arg_crash_chvt, "Manager" }, + { "CPUAffinity", config_parse_cpu_affinity, NULL, "Manager" }, + { NULL, NULL, NULL, NULL } + }; + + static const char * const sections[] = { + "Manager", + NULL + }; + + FILE *f; + const char *fn; + int r; + + fn = arg_running_as == MANAGER_SYSTEM ? SYSTEM_CONFIG_FILE : SESSION_CONFIG_FILE; + + if (!(f = fopen(fn, "re"))) { + if (errno == ENOENT) + return 0; + + log_warning("Failed to open configuration file '%s': %m", fn); + return 0; + } + + if ((r = config_parse(fn, f, sections, items, false, NULL)) < 0) + log_warning("Failed to parse configuration file: %s", strerror(-r)); + + fclose(f); + + return 0; +} + static int parse_proc_cmdline(void) { char *line; int r; @@ -694,6 +858,9 @@ int main(int argc, char *argv[]) { /* If we are init, we can block sigkill. Yay. */ ignore_signals(SIGNALS_IGNORE, -1); + if (parse_config_file() < 0) + goto finish; + if (arg_running_as == MANAGER_SYSTEM) if (parse_proc_cmdline() < 0) goto finish; diff --git a/src/system.conf b/src/system.conf new file mode 100644 index 0000000000..20218d1bee --- /dev/null +++ b/src/system.conf @@ -0,0 +1,19 @@ +# 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.conf(5) for details + +[Manager] +#LogLevel=info +#LogTarget=syslog-or-kmsg +#LogColor=yes +#LogLocation=no +#DumpCore=yes +#CrashShell=no +#ShowStatus=yes +#CrashChVT=1 +#CPUAffinity=1 2 |