From 8750a06b6caa9c1d33872cb7b0fa077497ef9888 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Thu, 20 Apr 2023 10:31:37 +0200 Subject: [PATCH] log: Add knob to disable kmsg ratelimiting This allows us to disable kmsg ratelimiting in the integration tests and mkosi for easier debugging. --- man/common-variables.xml | 8 ++++++++ man/kernel-command-line.xml | 1 + man/systemd.xml | 14 +++++++++++--- src/basic/log.c | 22 +++++++++++++++++++++- 4 files changed, 41 insertions(+), 4 deletions(-) diff --git a/man/common-variables.xml b/man/common-variables.xml index 0e220b3f9eb..81425e57e20 100644 --- a/man/common-variables.xml +++ b/man/common-variables.xml @@ -81,6 +81,14 @@ + + $SYSTEMD_LOG_RATELIMIT_KMSG + + Whether to ratelimit kmsg or not. Takes a boolean. + Defaults to true. If disabled, systemd will not ratelimit messages written to kmsg. + + + $SYSTEMD_PAGER diff --git a/man/kernel-command-line.xml b/man/kernel-command-line.xml index 27ef72da361..09f8ace4de6 100644 --- a/man/kernel-command-line.xml +++ b/man/kernel-command-line.xml @@ -66,6 +66,7 @@ systemd.log_level= systemd.log_location= systemd.log_color + systemd.log_ratelimit_kmsg systemd.default_standard_output= systemd.default_standard_error= systemd.setenv= diff --git a/man/systemd.xml b/man/systemd.xml index 1a68301d50b..ca9e4e99880 100644 --- a/man/systemd.xml +++ b/man/systemd.xml @@ -680,6 +680,11 @@ This can be overridden with . + + $SYSTEMD_LOG_RATELIMIT_KMSG + + + $XDG_CONFIG_HOME $XDG_CONFIG_DIRS @@ -865,13 +870,16 @@ systemd.log_target= systemd.log_time systemd.log_tid + systemd.log_ratelimit_kmsg Controls log output, with the same effect as the $SYSTEMD_LOG_COLOR, $SYSTEMD_LOG_LEVEL, $SYSTEMD_LOG_LOCATION, $SYSTEMD_LOG_TARGET, - $SYSTEMD_LOG_TIME, and $SYSTEMD_LOG_TID environment variables - described above. systemd.log_color, systemd.log_location, - systemd.log_time, and systemd.log_tid= can be specified without + $SYSTEMD_LOG_TIME, $SYSTEMD_LOG_TID and + $SYSTEMD_LOG_RATELIMIT_KMSG environment variables described above. + systemd.log_color, systemd.log_location, + systemd.log_time, systemd.log_tid and + systemd.log_ratelimit_kmsg can be specified without an argument, with the same effect as a positive boolean. diff --git a/src/basic/log.c b/src/basic/log.c index 75f59c43431..d0fef3554f5 100644 --- a/src/basic/log.c +++ b/src/basic/log.c @@ -50,6 +50,7 @@ static void *log_syntax_callback_userdata = NULL; static LogTarget log_target = LOG_TARGET_CONSOLE; static int log_max_level = LOG_INFO; static int log_facility = LOG_DAEMON; +static bool ratelimit_kmsg = true; static int console_fd = STDERR_FILENO; static int syslog_fd = -EBADF; @@ -552,7 +553,7 @@ static int write_to_kmsg( if (kmsg_fd < 0) return 0; - if (!ratelimit_below(&ratelimit)) + if (ratelimit_kmsg && !ratelimit_below(&ratelimit)) return 0; xsprintf(header_priority, "<%i>", level); @@ -1178,6 +1179,17 @@ int log_set_max_level_from_string(const char *e) { return 0; } +static int log_set_ratelimit_kmsg_from_string(const char *e) { + int r; + + r = parse_boolean(e); + if (r < 0) + return r; + + ratelimit_kmsg = r; + return 0; +} + static int parse_proc_cmdline_item(const char *key, const char *value, void *data) { /* @@ -1228,6 +1240,10 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat if (log_show_time_from_string(value ?: "1") < 0) log_warning("Failed to parse log time setting '%s'. Ignoring.", value); + } else if (proc_cmdline_key_streq(key, "systemd.log_ratelimit_kmsg")) { + + if (log_set_ratelimit_kmsg_from_string(value ?: "1") < 0) + log_warning("Failed to parse log ratelimit kmsg boolean '%s'. Ignoring.", value); } return 0; @@ -1268,6 +1284,10 @@ void log_parse_environment_variables(void) { e = getenv("SYSTEMD_LOG_TID"); if (e && log_show_tid_from_string(e) < 0) log_warning("Failed to parse log tid '%s'. Ignoring.", e); + + e = getenv("SYSTEMD_LOG_RATELIMIT_KMSG"); + if (e && log_set_ratelimit_kmsg_from_string(e) < 0) + log_warning("Failed to parse log ratelimit kmsg boolean '%s'. Ignoring.", e); } void log_parse_environment(void) {