]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: also stash executor path in Manager
authorMike Yuan <me@yhndnzj.com>
Fri, 4 Apr 2025 13:52:17 +0000 (15:52 +0200)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 4 Apr 2025 17:33:00 +0000 (02:33 +0900)
Prompted by b58c240312a5cc0f9f9eab3018d6459e44d085e0

Let's not query it over and over again in exec_spawn().

src/core/execute.c
src/core/manager.c
src/core/manager.h

index 3bc80cd643643519078460da320604ae8a3b0c78..e5ae2ee7a1cf3f3ec3f9ee3e082d9f2bce04b2f2 100644 (file)
@@ -473,7 +473,7 @@ int exec_spawn(
                 const CGroupContext *cgroup_context,
                 PidRef *ret) {
 
-        _cleanup_free_ char *subcgroup_path = NULL, *max_log_levels = NULL, *executor_path = NULL;
+        _cleanup_free_ char *subcgroup_path = NULL, *max_log_levels = NULL;
         _cleanup_fdset_free_ FDSet *fdset = NULL;
         _cleanup_fclose_ FILE *f = NULL;
         int r;
@@ -481,6 +481,7 @@ int exec_spawn(
         assert(unit);
         assert(unit->manager);
         assert(unit->manager->executor_fd >= 0);
+        assert(unit->manager->executor_path);
         assert(command);
         assert(context);
         assert(params);
@@ -551,10 +552,6 @@ int exec_spawn(
         if (r < 0)
                 return log_unit_error_errno(unit, r, "Failed to convert max log levels to string: %m");
 
-        r = fd_get_path(unit->manager->executor_fd, &executor_path);
-        if (r < 0)
-                return log_unit_error_errno(unit, r, "Failed to get executor path from fd: %m");
-
         char serialization_fd_number[DECIMAL_STR_MAX(int)];
         xsprintf(serialization_fd_number, "%i", fileno(f));
 
@@ -574,7 +571,7 @@ int exec_spawn(
         /* The executor binary is pinned, to avoid compatibility problems during upgrades. */
         r = posix_spawn_wrapper(
                         FORMAT_PROC_FD_PATH(unit->manager->executor_fd),
-                        STRV_MAKE(executor_path,
+                        STRV_MAKE(unit->manager->executor_path,
                                   "--deserialize", serialization_fd_number,
                                   "--log-level", max_log_levels,
                                   "--log-target", log_target_to_string(manager_get_executor_log_target(unit->manager))),
index 02623be4bf68842bfa6c5e73da9d64541512513a..66840407b5ff3d4416b67209059fc91bfc7acda7 100644 (file)
@@ -1048,16 +1048,11 @@ int manager_new(RuntimeScope runtime_scope, ManagerTestRunFlags test_run_flags,
         }
 
         if (!FLAGS_SET(test_run_flags, MANAGER_TEST_DONT_OPEN_EXECUTOR)) {
-                m->executor_fd = pin_callout_binary(SYSTEMD_EXECUTOR_BINARY_PATH, /* ret_path = */ NULL);
+                m->executor_fd = pin_callout_binary(SYSTEMD_EXECUTOR_BINARY_PATH, &m->executor_path);
                 if (m->executor_fd < 0)
                         return log_debug_errno(m->executor_fd, "Failed to pin executor binary: %m");
 
-                if (DEBUG_LOGGING) {
-                        _cleanup_free_ char *executor_path = NULL;
-
-                        (void) fd_get_path(m->executor_fd, &executor_path);
-                        log_debug("Using systemd-executor binary from '%s'.", strna(executor_path));
-                }
+                log_debug("Using systemd-executor binary from '%s'.", m->executor_path);
         }
 
         /* Note that we do not set up the notify fd here. We do that after deserialization,
@@ -1827,6 +1822,7 @@ Manager* manager_free(Manager *m) {
 #endif
 
         safe_close(m->executor_fd);
+        free(m->executor_path);
 
         return mfree(m);
 }
index 66ad04baf5421a96d6c6477d0de3eef5ea5c0bd1..e42ee3dd36eb8a5e80d6df66bf74baeb6846d3c5 100644 (file)
@@ -510,6 +510,7 @@ struct Manager {
 
         /* Pin the systemd-executor binary, so that it never changes until re-exec, ensuring we don't have
          * serialization/deserialization compatibility issues during upgrades. */
+        char *executor_path;
         int executor_fd;
 
         unsigned soft_reboots_count;