]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/exec-util: fix logging of the args of an executed program
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 19 Nov 2024 15:56:17 +0000 (16:56 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 27 Mar 2025 11:04:43 +0000 (12:04 +0100)
The debug logs has lots of "About to execute /some/path (null)". This
occurs when the args array is empty. Instead, only print "(null)" if
we failed with oom.

Having strv_skip() return NULL makes this pleasant to write without repeating
strv_isempty() a few times.

src/shared/exec-util.c

index bc997a9383c83e4ed1ad16c86483149861b8b1d4..01c6d74a00a1aac40ba96c1776dec1bd75e83202 100644 (file)
@@ -146,11 +146,13 @@ static int do_execute(
                 }
 
                 if (DEBUG_LOGGING) {
-                        _cleanup_free_ char *args = NULL;
-                        if (argv)
-                                args = quote_command_line(strv_skip(argv, 1), SHELL_ESCAPE_EMPTY);
+                        _cleanup_free_ char *s = NULL;
 
-                        log_debug("About to execute %s%s%s", t, argv ? " " : "", argv ? strnull(args) : "");
+                        char **args = strv_skip(argv, 1);
+                        if (args)
+                                s = quote_command_line(args, SHELL_ESCAPE_EMPTY);
+
+                        log_debug("About to execute %s%s%s", t, args ? " " : "", args ? strnull(s) : "");
                 }
 
                 if (FLAGS_SET(flags, EXEC_DIR_WARN_WORLD_WRITABLE)) {