diff options
author | Lennart Poettering <lennart@poettering.net> | 2014-08-15 18:07:36 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2014-08-15 18:07:36 +0200 |
commit | 1de1c9c37bb58d99c3f9d86f50212e641a2948b4 (patch) | |
tree | 55e2711b41b4b7c24856d5b1e2af1b949c15a240 /src/shared | |
parent | 56d96fc00cd009e92e611c11f15c1bfb1b1eb9e8 (diff) |
main,log: parse the log related kernel command line parameters at one place only, and for all tools
Previously, we ended up parsing some of them three times: in main.c when
processing the kernel cmdline, in main.c when processing the process
cmdline (only for containers), and in log.c again.
Let's streamline this, and only parse them in log.c
In PID 1 also make sure we parse "quiet" first, and then override this
with the more specific checks in log.c
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/log.c | 54 |
1 files changed, 37 insertions, 17 deletions
diff --git a/src/shared/log.c b/src/shared/log.c index 2bac998bcd..b730ac921a 100644 --- a/src/shared/log.c +++ b/src/shared/log.c @@ -871,27 +871,47 @@ int log_set_max_level_from_string(const char *e) { return 0; } +static int parse_proc_cmdline_item(const char *key, const char *value) { + + /* + * The systemd.log_xyz= settings are parsed by all tools, and + * so is "debug". + * + * However, "quiet" is only parsed by PID 1! + */ + + if (streq(key, "debug") && !value) + log_set_max_level(LOG_DEBUG); + + else if (streq(key, "systemd.log_target") && value) { + + if (log_set_target_from_string(value) < 0) + log_warning("Failed to parse log target '%s'. Ignoring.", value); + + } else if (streq(key, "systemd.log_level") && value) { + + if (log_set_max_level_from_string(value) < 0) + log_warning("Failed to parse log level '%s'. Ignoring.", value); + + } else if (streq(key, "systemd.log_color") && value) { + + if (log_show_color_from_string(value) < 0) + log_warning("Failed to parse log color setting '%s'. Ignoring.", value); + + } else if (streq(key, "systemd.log_location") && value) { + + if (log_show_location_from_string(value) < 0) + log_warning("Failed to parse log location setting '%s'. Ignoring.", value); + } + + return 0; +} + void log_parse_environment(void) { _cleanup_free_ char *line = NULL; const char *e; - int r; - r = proc_cmdline(&line); - if (r < 0) - log_warning("Failed to read /proc/cmdline. Ignoring: %s", strerror(-r)); - else if (r > 0) { - const char *word, *state; - size_t l; - - FOREACH_WORD_QUOTED(word, l, line, state) { - if (l == 5 && startswith(word, "debug")) { - log_set_max_level(LOG_DEBUG); - break; - } - } - if (!isempty(state)) - log_warning("Trailing garbage and the end of kernel commandline, ignoring."); - } + parse_proc_cmdline(parse_proc_cmdline_item); e = secure_getenv("SYSTEMD_LOG_TARGET"); if (e && log_set_target_from_string(e) < 0) |