summaryrefslogtreecommitdiff
path: root/src/basic
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2023-04-20 16:34:12 +0200
committerGitHub <noreply@github.com>2023-04-20 16:34:12 +0200
commit18010d394bcee5e8865aa1834b3de767cb09d710 (patch)
tree63f775af2d084b582243f2f37359da383b1bbf96 /src/basic
parent14ce246771a72c7e0e493375016030b0bcbc15fc (diff)
parenta93aaede294258e51e4e2a6a9530ae0d29a45915 (diff)
downloadsystemd-18010d394bcee5e8865aa1834b3de767cb09d710.tar.gz
Merge pull request #27327 from DaanDeMeyer/hotplug
kmod-setup: Add early loading for virtio_console
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/log.c28
-rw-r--r--src/basic/string-util.c12
-rw-r--r--src/basic/string-util.h5
-rw-r--r--src/basic/strv.h12
4 files changed, 43 insertions, 14 deletions
diff --git a/src/basic/log.c b/src/basic/log.c
index 75f59c4343..4cd2d5a4ab 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,8 +553,12 @@ static int write_to_kmsg(
if (kmsg_fd < 0)
return 0;
- if (!ratelimit_below(&ratelimit))
- return 0;
+ if (ratelimit_kmsg && !ratelimit_below(&ratelimit)) {
+ if (ratelimit_num_dropped(&ratelimit) > 1)
+ return 0;
+
+ buffer = "Too many messages being logged to kmsg, ignoring";
+ }
xsprintf(header_priority, "<%i>", level);
xsprintf(header_pid, "["PID_FMT"]: ", getpid_cached());
@@ -1178,6 +1183,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 +1244,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 +1288,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) {
diff --git a/src/basic/string-util.c b/src/basic/string-util.c
index cc2f8ecdab..c74ee67dfe 100644
--- a/src/basic/string-util.c
+++ b/src/basic/string-util.c
@@ -1283,3 +1283,15 @@ char *find_line_startswith(const char *haystack, const char *needle) {
return p + strlen(needle);
}
+
+char *startswith_strv(const char *string, char **strv) {
+ char *found = NULL;
+
+ STRV_FOREACH(i, strv) {
+ found = startswith(string, *i);
+ if (found)
+ break;
+ }
+
+ return found;
+}
diff --git a/src/basic/string-util.h b/src/basic/string-util.h
index 75483924af..4430910e22 100644
--- a/src/basic/string-util.h
+++ b/src/basic/string-util.h
@@ -267,3 +267,8 @@ char *strdupspn(const char *a, const char *accept);
char *strdupcspn(const char *a, const char *reject);
char *find_line_startswith(const char *haystack, const char *needle);
+
+char *startswith_strv(const char *string, char **strv);
+
+#define STARTSWITH_SET(p, ...) \
+ startswith_strv(p, STRV_MAKE(__VA_ARGS__))
diff --git a/src/basic/strv.h b/src/basic/strv.h
index b4d3f121f9..544d46a3f8 100644
--- a/src/basic/strv.h
+++ b/src/basic/strv.h
@@ -200,18 +200,6 @@ static inline void strv_print(char * const *l) {
_x && strv_contains_case(STRV_MAKE(__VA_ARGS__), _x); \
})
-#define STARTSWITH_SET(p, ...) \
- ({ \
- const char *_p = (p); \
- char *_found = NULL; \
- STRV_FOREACH(_i, STRV_MAKE(__VA_ARGS__)) { \
- _found = startswith(_p, *_i); \
- if (_found) \
- break; \
- } \
- _found; \
- })
-
#define ENDSWITH_SET(p, ...) \
({ \
const char *_p = (p); \