summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDaan De Meyer <daan.j.demeyer@gmail.com>2024-07-31 13:11:51 +0200
committerDaan De Meyer <daan.j.demeyer@gmail.com>2024-07-31 13:12:55 +0200
commit7881f485c9f57b1c7de4308eeab54458890c5c19 (patch)
tree8c752215b83b23918da4eba05f9e3616faa8be56 /src
parentkernel-install: Try some more initrd variants in 90-loaderentry.install (diff)
downloadsystemd-7881f485c9f57b1c7de4308eeab54458890c5c19.tar.xz
systemd-7881f485c9f57b1c7de4308eeab54458890c5c19.zip
execute: Drop log level to unit log level in exec_spawn()
All messages logged from exec_spawn() are attributed to the unit and as such we should set the log level to the unit's max log level for the duration of the function.
Diffstat (limited to 'src')
-rw-r--r--src/basic/log.c5
-rw-r--r--src/basic/log.h11
-rw-r--r--src/core/execute.c1
3 files changed, 15 insertions, 2 deletions
diff --git a/src/basic/log.c b/src/basic/log.c
index a8056d2635..09500f9cb0 100644
--- a/src/basic/log.c
+++ b/src/basic/log.c
@@ -396,9 +396,10 @@ void log_forget_fds(void) {
console_fd_is_tty = -1;
}
-void log_set_max_level(int level) {
+int log_set_max_level(int level) {
assert(level == LOG_NULL || LOG_PRI(level) == level);
+ int old = log_max_level;
log_max_level = level;
/* Also propagate max log level to libc's syslog(), just in case some other component loaded into our
@@ -411,6 +412,8 @@ void log_set_max_level(int level) {
/* Ensure that our own LOG_NULL define maps sanely to the log mask */
assert_cc(LOG_UPTO(LOG_NULL) == 0);
+
+ return old;
}
void log_set_facility(int facility) {
diff --git a/src/basic/log.h b/src/basic/log.h
index 2da6d5767d..0412e8a871 100644
--- a/src/basic/log.h
+++ b/src/basic/log.h
@@ -56,7 +56,7 @@ int log_set_target_from_string(const char *e);
LogTarget log_get_target(void) _pure_;
void log_settle_target(void);
-void log_set_max_level(int level);
+int log_set_max_level(int level);
int log_set_max_level_from_string(const char *e);
int log_get_max_level(void) _pure_;
int log_max_levels_to_string(int level, char **ret);
@@ -491,6 +491,15 @@ size_t log_context_num_contexts(void);
/* Returns the number of fields in all attached log contexts. */
size_t log_context_num_fields(void);
+static inline void _reset_log_level(int *saved_log_level) {
+ assert(saved_log_level);
+
+ log_set_max_level(*saved_log_level);
+}
+
+#define LOG_CONTEXT_SET_LOG_LEVEL(level) \
+ _cleanup_(_reset_log_level) _unused_ int _saved_log_level_ = log_set_max_level(level);
+
#define LOG_CONTEXT_PUSH(...) \
LOG_CONTEXT_PUSH_STRV(STRV_MAKE(__VA_ARGS__))
diff --git a/src/core/execute.c b/src/core/execute.c
index cdc1277956..26b2c0fb4a 100644
--- a/src/core/execute.c
+++ b/src/core/execute.c
@@ -396,6 +396,7 @@ int exec_spawn(
assert(ret);
LOG_CONTEXT_PUSH_UNIT(unit);
+ LOG_CONTEXT_SET_LOG_LEVEL(context->log_level_max >= 0 ? context->log_level_max : log_get_max_level());
r = exec_context_load_environment(unit, context, &params->files_env);
if (r < 0)