From: Yu Watanabe Date: Sat, 23 Dec 2023 18:29:07 +0000 (+0900) Subject: core/executor: use log level specified in LogLevelMax= X-Git-Tag: v256-rc1~1403 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=36013380a93e78bb9c361419607e2c6ced0f7db5;p=thirdparty%2Fsystemd.git core/executor: use log level specified in LogLevelMax= Follow-up for cc9f4cad8cd759ab55048dc7a3eaa2c2fb0344da. Otherwise, still unexpected lines may be logged by executor. --- diff --git a/src/core/exec-invoke.c b/src/core/exec-invoke.c index 0475a3cc3ca..f76db133b11 100644 --- a/src/core/exec-invoke.c +++ b/src/core/exec-invoke.c @@ -3944,6 +3944,8 @@ int exec_invoke( assert(params); assert(exit_status); + /* This should be mostly redundant, as the log level is also passed as an argument of the executor, + * and is already applied earlier. Just for safety. */ if (context->log_level_max >= 0) log_set_max_level(context->log_level_max); diff --git a/src/core/execute-serialize.c b/src/core/execute-serialize.c index b67a4f9141c..55d24094f77 100644 --- a/src/core/execute-serialize.c +++ b/src/core/execute-serialize.c @@ -2153,6 +2153,8 @@ static int exec_context_serialize(const ExecContext *c, FILE *f) { if (r < 0) return r; + /* This is also passed to executor as an argument. So, the information should be redundant in general. + * But, let's keep this as is for consistency with other elements of ExecContext. See exec_spawn(). */ r = serialize_item_format(f, "exec-context-log-level-max", "%d", c->log_level_max); if (r < 0) return r; @@ -3096,6 +3098,7 @@ static int exec_context_deserialize(ExecContext *c, FILE *f) { if (r < 0) return r; } else if ((val = startswith(l, "exec-context-log-level-max="))) { + /* See comment in serialization. */ r = safe_atoi(val, &c->log_level_max); if (r < 0) return r; diff --git a/src/core/execute.c b/src/core/execute.c index e400d800847..e71763763c4 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -434,7 +434,10 @@ int exec_spawn(Unit *unit, if (r < 0) return log_unit_error_errno(unit, r, "Failed to set O_CLOEXEC on serialized fds: %m"); - r = log_level_to_string_alloc(log_get_max_level(), &log_level); + /* If LogLevelMax= is specified, then let's use the specified log level at the beginning of the + * executor process. To achieve that the specified log level is passed as an argument, rather than + * the one for the manager process. */ + r = log_level_to_string_alloc(context->log_level_max >= 0 ? context->log_level_max : log_get_max_level(), &log_level); if (r < 0) return log_unit_error_errno(unit, r, "Failed to convert log level to string: %m");