1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-23 21:35:11 +03:00

journald: convert journald to use parse_proc_cmdline

This makes journald use the common option parsing functionality.
One behavioural change is implemented:
"systemd.journald.forward_to_syslog" is now equivalent to
"systemd.journald.forward_to_syslog=1".
I think it's nicer to use this way.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2016-10-22 14:25:30 -04:00
parent 96287a4916
commit 5707ecf300
2 changed files with 74 additions and 92 deletions

View File

@ -301,22 +301,21 @@
<term><varname>ForwardToConsole=</varname></term> <term><varname>ForwardToConsole=</varname></term>
<term><varname>ForwardToWall=</varname></term> <term><varname>ForwardToWall=</varname></term>
<listitem><para>Control whether log messages received by the <listitem><para>Control whether log messages received by the journal daemon shall
journal daemon shall be forwarded to a traditional syslog be forwarded to a traditional syslog daemon, to the kernel log buffer (kmsg), to
daemon, to the kernel log buffer (kmsg), to the system the system console, or sent as wall messages to all logged-in users. These
console, or sent as wall messages to all logged-in users. options take boolean arguments. If forwarding to syslog is enabled but nothing
These options take boolean arguments. If forwarding to syslog reads messages from the socket, forwarding to syslog has no effect. By default,
is enabled but nothing reads messages from the socket, only forwarding to wall is enabled. These settings may be overridden at boot time
forwarding to syslog has no effect. By default, only with the kernel command line options
forwarding to wall is enabled. These settings may be <literal>systemd.journald.forward_to_syslog</literal>,
overridden at boot time with the kernel command line options <literal>systemd.journald.forward_to_kmsg</literal>,
<literal>systemd.journald.forward_to_syslog=</literal>, <literal>systemd.journald.forward_to_console</literal>, and
<literal>systemd.journald.forward_to_kmsg=</literal>, <literal>systemd.journald.forward_to_wall</literal>. If the option name is
<literal>systemd.journald.forward_to_console=</literal>, and specified without <literal>=</literal> and the following argument, true is
<literal>systemd.journald.forward_to_wall=</literal>. When assumed. Otherwise, the argument is parsed as a boolean. When forwarding to the
forwarding to the console, the TTY to log to can be changed console, the TTY to log to can be changed with <varname>TTYPath=</varname>,
with <varname>TTYPath=</varname>, described described below.</para></listitem>
below.</para></listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>

View File

@ -1528,85 +1528,68 @@ static int setup_signals(Server *s) {
return 0; return 0;
} }
static int server_parse_proc_cmdline(Server *s) { static int parse_proc_cmdline_item(const char *key, const char *value, void *data) {
_cleanup_free_ char *line = NULL; Server *s = data;
const char *p;
int r; int r;
r = proc_cmdline(&line); assert(s);
if (r < 0) {
log_warning_errno(r, "Failed to read /proc/cmdline, ignoring: %m");
return 0;
}
p = line; if (streq(key, "systemd.journald.forward_to_syslog")) {
for (;;) { r = value ? parse_boolean(value) : true;
_cleanup_free_ char *word = NULL;
r = extract_first_word(&p, &word, NULL, 0);
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to parse journald syntax \"%s\": %m", line); log_warning("Failed to parse forward to syslog switch \"%s\". Ignoring.", value);
else
if (r == 0) s->forward_to_syslog = r;
break; } else if (streq(key, "systemd.journald.forward_to_kmsg")) {
r = value ? parse_boolean(value) : true;
if (startswith(word, "systemd.journald.forward_to_syslog=")) { if (r < 0)
r = parse_boolean(word + 35); log_warning("Failed to parse forward to kmsg switch \"%s\". Ignoring.", value);
if (r < 0) else
log_warning("Failed to parse forward to syslog switch %s. Ignoring.", word + 35); s->forward_to_kmsg = r;
else } else if (streq(key, "systemd.journald.forward_to_console")) {
s->forward_to_syslog = r; r = value ? parse_boolean(value) : true;
} else if (startswith(word, "systemd.journald.forward_to_kmsg=")) { if (r < 0)
r = parse_boolean(word + 33); log_warning("Failed to parse forward to console switch \"%s\". Ignoring.", value);
if (r < 0) else
log_warning("Failed to parse forward to kmsg switch %s. Ignoring.", word + 33); s->forward_to_console = r;
else } else if (streq(key, "systemd.journald.forward_to_wall")) {
s->forward_to_kmsg = r; r = value ? parse_boolean(value) : true;
} else if (startswith(word, "systemd.journald.forward_to_console=")) { if (r < 0)
r = parse_boolean(word + 36); log_warning("Failed to parse forward to wall switch \"%s\". Ignoring.", value);
if (r < 0) else
log_warning("Failed to parse forward to console switch %s. Ignoring.", word + 36); s->forward_to_wall = r;
else } else if (streq(key, "systemd.journald.max_level_console") && value) {
s->forward_to_console = r; r = log_level_from_string(value);
} else if (startswith(word, "systemd.journald.forward_to_wall=")) { if (r < 0)
r = parse_boolean(word + 33); log_warning("Failed to parse max level console value \"%s\". Ignoring.", value);
if (r < 0) else
log_warning("Failed to parse forward to wall switch %s. Ignoring.", word + 33); s->max_level_console = r;
else } else if (streq(key, "systemd.journald.max_level_store") && value) {
s->forward_to_wall = r; r = log_level_from_string(value);
} else if (startswith(word, "systemd.journald.max_level_console=")) { if (r < 0)
r = log_level_from_string(word + 35); log_warning("Failed to parse max level store value \"%s\". Ignoring.", value);
if (r < 0) else
log_warning("Failed to parse max level console value %s. Ignoring.", word + 35); s->max_level_store = r;
else } else if (streq(key, "systemd.journald.max_level_syslog") && value) {
s->max_level_console = r; r = log_level_from_string(value);
} else if (startswith(word, "systemd.journald.max_level_store=")) { if (r < 0)
r = log_level_from_string(word + 33); log_warning("Failed to parse max level syslog value \"%s\". Ignoring.", value);
if (r < 0) else
log_warning("Failed to parse max level store value %s. Ignoring.", word + 33); s->max_level_syslog = r;
else } else if (streq(key, "systemd.journald.max_level_kmsg") && value) {
s->max_level_store = r; r = log_level_from_string(value);
} else if (startswith(word, "systemd.journald.max_level_syslog=")) { if (r < 0)
r = log_level_from_string(word + 34); log_warning("Failed to parse max level kmsg value \"%s\". Ignoring.", value);
if (r < 0) else
log_warning("Failed to parse max level syslog value %s. Ignoring.", word + 34); s->max_level_kmsg = r;
else } else if (streq(key, "systemd.journald.max_level_wall") && value) {
s->max_level_syslog = r; r = log_level_from_string(value);
} else if (startswith(word, "systemd.journald.max_level_kmsg=")) { if (r < 0)
r = log_level_from_string(word + 32); log_warning("Failed to parse max level wall value \"%s\". Ignoring.", value);
if (r < 0) else
log_warning("Failed to parse max level kmsg value %s. Ignoring.", word + 32); s->max_level_wall = r;
else } else if (startswith(key, "systemd.journald"))
s->max_level_kmsg = r; log_warning("Unknown journald kernel command line option \"%s\". Ignoring.", key);
} else if (startswith(word, "systemd.journald.max_level_wall=")) {
r = log_level_from_string(word + 32);
if (r < 0)
log_warning("Failed to parse max level wall value %s. Ignoring.", word + 32);
else
s->max_level_wall = r;
} else if (startswith(word, "systemd.journald"))
log_warning("Invalid systemd.journald parameter. Ignoring.");
}
/* do not warn about state here, since probably systemd already did */ /* do not warn about state here, since probably systemd already did */
return 0; return 0;
@ -1917,7 +1900,7 @@ int server_init(Server *s) {
journal_reset_metrics(&s->runtime_storage.metrics); journal_reset_metrics(&s->runtime_storage.metrics);
server_parse_config_file(s); server_parse_config_file(s);
server_parse_proc_cmdline(s); parse_proc_cmdline(parse_proc_cmdline_item, s);
if (!!s->rate_limit_interval ^ !!s->rate_limit_burst) { if (!!s->rate_limit_interval ^ !!s->rate_limit_burst) {
log_debug("Setting both rate limit interval and burst from "USEC_FMT",%u to 0,0", log_debug("Setting both rate limit interval and burst from "USEC_FMT",%u to 0,0",