core/executor: use log level specified in LogLevelMax=

Follow-up for cc9f4cad8c.

Otherwise, still unexpected lines may be logged by executor.
This commit is contained in:
Yu Watanabe
2023-12-24 03:29:07 +09:00
parent 08ba85c71e
commit 36013380a9
3 changed files with 9 additions and 1 deletions

View File

@@ -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);

View File

@@ -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;

View File

@@ -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");