]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
various: add a fixed name to log about plugin execution 38794/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 1 Sep 2025 11:52:35 +0000 (13:52 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 3 Sep 2025 06:56:23 +0000 (08:56 +0200)
Function execute_directories logged in a way that was meaningless
without additional context:
  systemd[1]: No executables found.
In execute_strv this was partially rectified by extracting the directory
name from one of the directories and using this as the identifier. But
the directory name is not always meaningful, and can also be set from
an environment variable. Let's simplify things by providing a fixed name
that can be used consistently in all log messages. In particular this will
make error messages easier to understand if users report just the error
without additional context.

src/core/manager.c
src/kernel-install/kernel-install.c
src/libsystemd/sd-path/path-lookup.c
src/shared/exec-util.c
src/shared/exec-util.h
src/shutdown/shutdown.c
src/sleep/sleep.c
src/test/test-exec-util.c

index d85896577f3e6b19452cae7e89346c1c99df6dd3..5bba7e81b0cf020ae0019441d6fd2a0b1ed30748 100644 (file)
@@ -3953,6 +3953,7 @@ static int manager_run_environment_generators(Manager *m) {
 
         WITH_UMASK(0022)
                 r = execute_directories(
+                                "environment-generators",
                                 (const char* const*) paths,
                                 DEFAULT_TIMEOUT_USEC,
                                 gather_environment,
@@ -4070,6 +4071,7 @@ static int manager_execute_generators(Manager *m, char * const *paths, bool remo
 
         BLOCK_WITH_UMASK(0022);
         return execute_directories(
+                        "generators",
                         (const char* const*) paths,
                         DEFAULT_TIMEOUT_USEC,
                         /* callbacks= */ NULL, /* callback_args= */ NULL,
index f17e99004b4423f79d52790d4383620ca4cd0129..a2faa0f85068a2ca365619351d59026dbfda0f2b 100644 (file)
@@ -1061,7 +1061,7 @@ static int context_execute(Context *c) {
         }
 
         ret = execute_strv(
-                        /* name = */ NULL,
+                        "plugins",
                         c->plugins,
                         /* root = */ NULL,
                         USEC_INFINITY,
index 3ddbda0e9f80561c86baa7f04f7b392470bbebbb..55d9d4353a1de389f95e6441bc039cb00f02698e 100644 (file)
@@ -678,7 +678,6 @@ static const char* const user_env_generator_paths[] = {
 };
 
 char** generator_binary_paths_internal(RuntimeScope scope, bool env_generator) {
-
         static const struct {
                 const char *env_name;
                 const char * const *paths[_RUNTIME_SCOPE_MAX];
index a64bcfe125137ef8c3b1fd8eb5e55ff677fe42a5..193b97c46753db5729155e209c45fa930e86f8d4 100644 (file)
@@ -243,13 +243,13 @@ int execute_strv(
         pid_t executor_pid;
         int r;
 
+        assert(name);
         assert(!FLAGS_SET(flags, EXEC_DIR_PARALLEL | EXEC_DIR_SKIP_REMAINING));
 
         if (strv_isempty(paths))
                 return 0;
 
         if (callbacks) {
-                assert(name);
                 assert(callbacks[STDOUT_GENERATE]);
                 assert(callbacks[STDOUT_COLLECT]);
                 assert(callbacks[STDOUT_CONSUME]);
@@ -257,14 +257,16 @@ int execute_strv(
 
                 fd = open_serialization_fd(name);
                 if (fd < 0)
-                        return log_error_errno(fd, "Failed to open serialization file: %m");
+                        return log_error_errno(fd, "Failed to open serialization file for %s: %m", name);
         }
 
         /* Executes all binaries in the directories serially or in parallel and waits for
          * them to finish. Optionally a timeout is applied. If a file with the same name
          * exists in more than one directory, the earliest one wins. */
 
-        r = safe_fork("(sd-exec-strv)", FORK_RESET_SIGNALS|FORK_DEATHSIG_SIGTERM|FORK_LOG, &executor_pid);
+        const char *process_name = strjoina("(", name, ")");
+
+        r = safe_fork(process_name, FORK_RESET_SIGNALS|FORK_DEATHSIG_SIGTERM|FORK_LOG, &executor_pid);
         if (r < 0)
                 return r;
         if (r == 0) {
@@ -272,7 +274,7 @@ int execute_strv(
                 _exit(r < 0 ? EXIT_FAILURE : r);
         }
 
-        r = wait_for_terminate_and_check("(sd-exec-strv)", executor_pid, 0);
+        r = wait_for_terminate_and_check(process_name, executor_pid, 0);
         if (r < 0)
                 return r;
         if (!FLAGS_SET(flags, EXEC_DIR_IGNORE_ERRORS) && r > 0)
@@ -283,16 +285,17 @@ int execute_strv(
 
         r = finish_serialization_fd(fd);
         if (r < 0)
-                return log_error_errno(r, "Failed to finish serialization fd: %m");
+                return log_error_errno(r, "Failed to finish serialization fd for %s: %m", name);
 
         r = callbacks[STDOUT_CONSUME](TAKE_FD(fd), callback_args[STDOUT_CONSUME]);
         if (r < 0)
-                return log_error_errno(r, "Failed to parse returned data: %m");
+                return log_error_errno(r, "Failed to parse returned data for %s: %m", name);
 
         return 0;
 }
 
 int execute_directories(
+                const char *name,
                 const char * const *directories,
                 usec_t timeout,
                 gather_stdout_callback_t const callbacks[_STDOUT_CONSUME_MAX],
@@ -302,9 +305,9 @@ int execute_directories(
                 ExecDirFlags flags) {
 
         _cleanup_strv_free_ char **paths = NULL;
-        _cleanup_free_ char *name = NULL;
         int r;
 
+        assert(name);
         assert(!strv_isempty((char* const*) directories));
 
         r = conf_files_list_strv(
@@ -314,19 +317,13 @@ int execute_directories(
                         CONF_FILES_EXECUTABLE|CONF_FILES_REGULAR|CONF_FILES_FILTER_MASKED,
                         directories);
         if (r < 0)
-                return log_error_errno(r, "Failed to enumerate executables: %m");
+                return log_error_errno(r, "%s: failed to enumerate executables: %m", name);
 
         if (strv_isempty(paths)) {
-                log_debug("No executables found.");
+                log_debug("%s: no executables found.", name);
                 return 0;
         }
 
-        if (callbacks) {
-                r = path_extract_filename(directories[0], &name);
-                if (r < 0)
-                        return log_error_errno(r, "Failed to extract file name from '%s': %m", directories[0]);
-        }
-
         return execute_strv(name, paths, /* root = */ NULL, timeout, callbacks, callback_args, argv, envp, flags);
 }
 
index fcc1ad065fd992faa90a361a9b8fb7ace2a1f22a..d6af5de5101050819bf84646c5115ed881d34545 100644 (file)
@@ -32,6 +32,7 @@ int execute_strv(
                 ExecDirFlags flags);
 
 int execute_directories(
+                const char *name,
                 const char * const *directories,
                 usec_t timeout,
                 gather_stdout_callback_t const callbacks[_STDOUT_CONSUME_MAX],
index 3317068e478ec7d397bc2e4bdb1e3b7394627e09..9a114d9be54dd663e9b7b1d9984c3447c9ec9732 100644 (file)
@@ -575,7 +575,15 @@ int main(int argc, char *argv[]) {
                 arg_verb,
                 NULL,
         };
-        (void) execute_directories(dirs, DEFAULT_TIMEOUT_USEC, NULL, NULL, (char**) arguments, NULL, EXEC_DIR_PARALLEL | EXEC_DIR_IGNORE_ERRORS);
+        (void) execute_directories(
+                        "system-shutdown",
+                        dirs,
+                        DEFAULT_TIMEOUT_USEC,
+                        /* callbacks= */ NULL,
+                        /* callback_args= */ NULL,
+                        (char**) arguments,
+                        /* envp= */ NULL,
+                        EXEC_DIR_PARALLEL | EXEC_DIR_IGNORE_ERRORS);
 
         (void) rlimit_nofile_safe();
 
index 3390ebe0c08ddf7bc0907c5c07459af6ff531143..3bfe4790888b229a7c72e1edf0bd5a539f5c61a9 100644 (file)
@@ -311,7 +311,15 @@ static int execute(
         if (setenv("SYSTEMD_SLEEP_ACTION", action, /* overwrite = */ 1) < 0)
                 log_warning_errno(errno, "Failed to set SYSTEMD_SLEEP_ACTION=%s, ignoring: %m", action);
 
-        (void) execute_directories(dirs, DEFAULT_TIMEOUT_USEC, NULL, NULL, (char **) arguments, NULL, EXEC_DIR_PARALLEL | EXEC_DIR_IGNORE_ERRORS);
+        (void) execute_directories(
+                        "system-sleep",
+                        dirs,
+                        DEFAULT_TIMEOUT_USEC,
+                        /* callbacks= */ NULL,
+                        /* callback_args= */ NULL,
+                        (char **) arguments,
+                        /* envp= */ NULL,
+                        EXEC_DIR_PARALLEL | EXEC_DIR_IGNORE_ERRORS);
         (void) lock_all_homes();
 
         log_struct(LOG_INFO,
@@ -332,8 +340,15 @@ static int execute(
                            LOG_ITEM("SLEEP=%s", sleep_operation_to_string(arg_operation)));
 
         arguments[1] = "post";
-        (void) execute_directories(dirs, DEFAULT_TIMEOUT_USEC, NULL, NULL, (char **) arguments, NULL, EXEC_DIR_PARALLEL | EXEC_DIR_IGNORE_ERRORS);
-
+        (void) execute_directories(
+                        "system-sleep",
+                        dirs,
+                        DEFAULT_TIMEOUT_USEC,
+                        /* callbacks= */ NULL,
+                        /* callback_args= */ NULL,
+                        (char **) arguments,
+                        /* envp= */ NULL,
+                        EXEC_DIR_PARALLEL | EXEC_DIR_IGNORE_ERRORS);
         if (r >= 0)
                 return 0;
 
index 6accb28b5657f3fc442d94cc7997779e422d6efb..e5258de81248f4969ff80eb534cdd29cb427a583 100644 (file)
@@ -117,9 +117,9 @@ static void test_execute_directory_one(bool gather_stdout) {
                 return;
 
         if (gather_stdout)
-                execute_directories(dirs, DEFAULT_TIMEOUT_USEC, ignore_stdout, ignore_stdout_args, NULL, NULL, EXEC_DIR_PARALLEL | EXEC_DIR_IGNORE_ERRORS);
+                execute_directories("test", dirs, DEFAULT_TIMEOUT_USEC, ignore_stdout, ignore_stdout_args, NULL, NULL, EXEC_DIR_PARALLEL | EXEC_DIR_IGNORE_ERRORS);
         else
-                execute_directories(dirs, DEFAULT_TIMEOUT_USEC, NULL, NULL, NULL, NULL, EXEC_DIR_PARALLEL | EXEC_DIR_IGNORE_ERRORS);
+                execute_directories("test", dirs, DEFAULT_TIMEOUT_USEC, NULL, NULL, NULL, NULL, EXEC_DIR_PARALLEL | EXEC_DIR_IGNORE_ERRORS);
 
         assert_se(chdir(tmp_lo) == 0);
         assert_se(access("it_works", F_OK) >= 0);
@@ -189,7 +189,9 @@ TEST(execution_order) {
         if (access(name, X_OK) < 0 && ERRNO_IS_PRIVILEGE(errno))
                 return;
 
-        execute_directories(dirs, DEFAULT_TIMEOUT_USEC, ignore_stdout, ignore_stdout_args, NULL, NULL, EXEC_DIR_PARALLEL | EXEC_DIR_IGNORE_ERRORS);
+        execute_directories(__func__,
+                            dirs, DEFAULT_TIMEOUT_USEC, ignore_stdout, ignore_stdout_args, NULL, NULL,
+                            EXEC_DIR_PARALLEL | EXEC_DIR_IGNORE_ERRORS);
 
         assert_se(read_full_file(output, &contents, NULL) >= 0);
         ASSERT_STREQ(contents, "30-override\n80-foo\n90-bar\nlast\n");
@@ -270,7 +272,8 @@ TEST(stdout_gathering) {
         if (access(name, X_OK) < 0 && ERRNO_IS_PRIVILEGE(errno))
                 return;
 
-        r = execute_directories(dirs, DEFAULT_TIMEOUT_USEC, gather_stdouts, args, NULL, NULL,
+        r = execute_directories(__func__,
+                                dirs, DEFAULT_TIMEOUT_USEC, gather_stdouts, args, NULL, NULL,
                                 EXEC_DIR_PARALLEL | EXEC_DIR_IGNORE_ERRORS);
         assert_se(r >= 0);
 
@@ -337,7 +340,9 @@ TEST(environment_gathering) {
         if (access(name, X_OK) < 0 && ERRNO_IS_PRIVILEGE(errno))
                 return;
 
-        r = execute_directories(dirs, DEFAULT_TIMEOUT_USEC, gather_environment, args, NULL, NULL, EXEC_DIR_PARALLEL | EXEC_DIR_IGNORE_ERRORS);
+        r = execute_directories(__func__,
+                                dirs, DEFAULT_TIMEOUT_USEC, gather_environment, args, NULL, NULL,
+                                EXEC_DIR_PARALLEL | EXEC_DIR_IGNORE_ERRORS);
         assert_se(r >= 0);
 
         STRV_FOREACH(p, env)
@@ -353,7 +358,9 @@ TEST(environment_gathering) {
         env = strv_new("PATH=" DEFAULT_PATH_WITHOUT_SBIN);
         assert_se(env);
 
-        r = execute_directories(dirs, DEFAULT_TIMEOUT_USEC, gather_environment, args, NULL, env, EXEC_DIR_PARALLEL | EXEC_DIR_IGNORE_ERRORS);
+        r = execute_directories(__func__,
+                                dirs, DEFAULT_TIMEOUT_USEC, gather_environment, args, NULL, env,
+                                EXEC_DIR_PARALLEL | EXEC_DIR_IGNORE_ERRORS);
         assert_se(r >= 0);
 
         STRV_FOREACH(p, env)
@@ -399,7 +406,8 @@ TEST(error_catching) {
         if (access(name, X_OK) < 0 && ERRNO_IS_PRIVILEGE(errno))
                 return;
 
-        r = execute_directories(dirs, DEFAULT_TIMEOUT_USEC,
+        r = execute_directories(__func__,
+                                dirs, DEFAULT_TIMEOUT_USEC,
                                 /* callbacks = */ NULL, /* callback_args = */ NULL,
                                 /* argv = */ NULL, /* envp = */ NULL, /* flags = */ 0);