]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/executor: use log level specified in LogLevelMax=
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 23 Dec 2023 18:29:07 +0000 (03:29 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 23 Dec 2023 21:44:03 +0000 (06:44 +0900)
Follow-up for cc9f4cad8cd759ab55048dc7a3eaa2c2fb0344da.

Otherwise, still unexpected lines may be logged by executor.

src/core/exec-invoke.c
src/core/execute-serialize.c
src/core/execute.c

index 0475a3cc3cacd28991659f79cf9e148acf358358..f76db133b114da6d28dae5c33b7a4f7e4c6029db 100644 (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);
 
index b67a4f9141c22c28ebbe62bfcb818aa6aabec8d2..55d24094f77f00ebd44263e6fd27bcad7ff42abc 100644 (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;
index e400d800847109c03eb96da84937779e9757f6c0..e71763763c47d78ea8d5ec75f80a39836483b29f 100644 (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");