]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journald: convert journald to use parse_proc_cmdline
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 22 Oct 2016 18:25:30 +0000 (14:25 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 22 Oct 2016 18:38:10 +0000 (14:38 -0400)
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.

man/journald.conf.xml
src/journal/journald-server.c

index df2e2246a1e7afe55981bcb1d7fae5a19fd1e16b..9daa9648039d6046cb0ec46ff03034f7105011b6 100644 (file)
         <term><varname>ForwardToConsole=</varname></term>
         <term><varname>ForwardToWall=</varname></term>
 
-        <listitem><para>Control whether log messages received by the
-        journal daemon shall be forwarded to a traditional syslog
-        daemon, to the kernel log buffer (kmsg), to the system
-        console, or sent as wall messages to all logged-in users.
-        These options take boolean arguments. If forwarding to syslog
-        is enabled but nothing reads messages from the socket,
-        forwarding to syslog has no effect. By default, only
-        forwarding to wall is enabled. These settings may be
-        overridden at boot time with the kernel command line options
-        <literal>systemd.journald.forward_to_syslog=</literal>,
-        <literal>systemd.journald.forward_to_kmsg=</literal>,
-        <literal>systemd.journald.forward_to_console=</literal>, and
-        <literal>systemd.journald.forward_to_wall=</literal>. When
-        forwarding to the console, the TTY to log to can be changed
-        with <varname>TTYPath=</varname>, described
-        below.</para></listitem>
+        <listitem><para>Control whether log messages received by the journal daemon shall
+        be forwarded to a traditional syslog daemon, to the kernel log buffer (kmsg), to
+        the system console, or sent as wall messages to all logged-in users.  These
+        options take boolean arguments. If forwarding to syslog is enabled but nothing
+        reads messages from the socket, forwarding to syslog has no effect. By default,
+        only forwarding to wall is enabled. These settings may be overridden at boot time
+        with the kernel command line options
+        <literal>systemd.journald.forward_to_syslog</literal>,
+        <literal>systemd.journald.forward_to_kmsg</literal>,
+        <literal>systemd.journald.forward_to_console</literal>, and
+        <literal>systemd.journald.forward_to_wall</literal>. If the option name is
+        specified without <literal>=</literal> and the following argument, true is
+        assumed. Otherwise, the argument is parsed as a boolean. When forwarding to the
+        console, the TTY to log to can be changed with <varname>TTYPath=</varname>,
+        described below.</para></listitem>
       </varlistentry>
 
       <varlistentry>
index 92c623d9e99466708e7913900375d65db60d1359..e7dcbba04f286474fec10a14aec40627714a5620 100644 (file)
@@ -1528,85 +1528,68 @@ static int setup_signals(Server *s) {
         return 0;
 }
 
-static int server_parse_proc_cmdline(Server *s) {
-        _cleanup_free_ char *line = NULL;
-        const char *p;
+static int parse_proc_cmdline_item(const char *key, const char *value, void *data) {
+        Server *s = data;
         int r;
 
-        r = proc_cmdline(&line);
-        if (r < 0) {
-                log_warning_errno(r, "Failed to read /proc/cmdline, ignoring: %m");
-                return 0;
-        }
-
-        p = line;
-        for (;;) {
-                _cleanup_free_ char *word = NULL;
+        assert(s);
 
-                r = extract_first_word(&p, &word, NULL, 0);
+        if (streq(key, "systemd.journald.forward_to_syslog")) {
+                r = value ? parse_boolean(value) : true;
                 if (r < 0)
-                        return log_error_errno(r, "Failed to parse journald syntax \"%s\": %m", line);
-
-                if (r == 0)
-                        break;
-
-                if (startswith(word, "systemd.journald.forward_to_syslog=")) {
-                        r = parse_boolean(word + 35);
-                        if (r < 0)
-                                log_warning("Failed to parse forward to syslog switch %s. Ignoring.", word + 35);
-                        else
-                                s->forward_to_syslog = r;
-                } else if (startswith(word, "systemd.journald.forward_to_kmsg=")) {
-                        r = parse_boolean(word + 33);
-                        if (r < 0)
-                                log_warning("Failed to parse forward to kmsg switch %s. Ignoring.", word + 33);
-                        else
-                                s->forward_to_kmsg = r;
-                } else if (startswith(word, "systemd.journald.forward_to_console=")) {
-                        r = parse_boolean(word + 36);
-                        if (r < 0)
-                                log_warning("Failed to parse forward to console switch %s. Ignoring.", word + 36);
-                        else
-                                s->forward_to_console = r;
-                } else if (startswith(word, "systemd.journald.forward_to_wall=")) {
-                        r = parse_boolean(word + 33);
-                        if (r < 0)
-                                log_warning("Failed to parse forward to wall switch %s. Ignoring.", word + 33);
-                        else
-                                s->forward_to_wall = r;
-                } else if (startswith(word, "systemd.journald.max_level_console=")) {
-                        r = log_level_from_string(word + 35);
-                        if (r < 0)
-                                log_warning("Failed to parse max level console value %s. Ignoring.", word + 35);
-                        else
-                                s->max_level_console = r;
-                } else if (startswith(word, "systemd.journald.max_level_store=")) {
-                        r = log_level_from_string(word + 33);
-                        if (r < 0)
-                                log_warning("Failed to parse max level store value %s. Ignoring.", word + 33);
-                        else
-                                s->max_level_store = r;
-                } else if (startswith(word, "systemd.journald.max_level_syslog=")) {
-                        r = log_level_from_string(word + 34);
-                        if (r < 0)
-                                log_warning("Failed to parse max level syslog value %s. Ignoring.", word + 34);
-                        else
-                                s->max_level_syslog = r;
-                } else if (startswith(word, "systemd.journald.max_level_kmsg=")) {
-                        r = log_level_from_string(word + 32);
-                        if (r < 0)
-                                log_warning("Failed to parse max level kmsg value %s. Ignoring.", word + 32);
-                        else
-                                s->max_level_kmsg = r;
-                } 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.");
-        }
+                        log_warning("Failed to parse forward to syslog switch \"%s\". Ignoring.", value);
+                else
+                        s->forward_to_syslog = r;
+        } else if (streq(key, "systemd.journald.forward_to_kmsg")) {
+                r = value ? parse_boolean(value) : true;
+                if (r < 0)
+                        log_warning("Failed to parse forward to kmsg switch \"%s\". Ignoring.", value);
+                else
+                        s->forward_to_kmsg = r;
+        } else if (streq(key, "systemd.journald.forward_to_console")) {
+                r = value ? parse_boolean(value) : true;
+                if (r < 0)
+                        log_warning("Failed to parse forward to console switch \"%s\". Ignoring.", value);
+                else
+                        s->forward_to_console = r;
+        } else if (streq(key, "systemd.journald.forward_to_wall")) {
+                r = value ? parse_boolean(value) : true;
+                if (r < 0)
+                        log_warning("Failed to parse forward to wall switch \"%s\". Ignoring.", value);
+                else
+                        s->forward_to_wall = r;
+        } else if (streq(key, "systemd.journald.max_level_console") && value) {
+                r = log_level_from_string(value);
+                if (r < 0)
+                        log_warning("Failed to parse max level console value \"%s\". Ignoring.", value);
+                else
+                        s->max_level_console = r;
+        } else if (streq(key, "systemd.journald.max_level_store") && value) {
+                r = log_level_from_string(value);
+                if (r < 0)
+                        log_warning("Failed to parse max level store value \"%s\". Ignoring.", value);
+                else
+                        s->max_level_store = r;
+        } else if (streq(key, "systemd.journald.max_level_syslog") && value) {
+                r = log_level_from_string(value);
+                if (r < 0)
+                        log_warning("Failed to parse max level syslog value \"%s\". Ignoring.", value);
+                else
+                        s->max_level_syslog = r;
+        } else if (streq(key, "systemd.journald.max_level_kmsg") && value) {
+                r = log_level_from_string(value);
+                if (r < 0)
+                        log_warning("Failed to parse max level kmsg value \"%s\". Ignoring.", value);
+                else
+                        s->max_level_kmsg = r;
+        } else if (streq(key, "systemd.journald.max_level_wall") && value) {
+                r = log_level_from_string(value);
+                if (r < 0)
+                        log_warning("Failed to parse max level wall value \"%s\". Ignoring.", value);
+                else
+                        s->max_level_wall = r;
+        } else if (startswith(key, "systemd.journald"))
+                log_warning("Unknown journald kernel command line option \"%s\". Ignoring.", key);
 
         /* do not warn about state here, since probably systemd already did */
         return 0;
@@ -1917,7 +1900,7 @@ int server_init(Server *s) {
         journal_reset_metrics(&s->runtime_storage.metrics);
 
         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) {
                 log_debug("Setting both rate limit interval and burst from "USEC_FMT",%u to 0,0",