From b157a7e6131beb6e56ce91d9a901b2dbfa5256f9 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Fri, 4 Apr 2025 15:52:17 +0200 Subject: [PATCH] core: also stash executor path in Manager Prompted by b58c240312a5cc0f9f9eab3018d6459e44d085e0 Let's not query it over and over again in exec_spawn(). --- src/core/execute.c | 9 +++------ src/core/manager.c | 10 +++------- src/core/manager.h | 1 + 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/core/execute.c b/src/core/execute.c index 3bc80cd6436..e5ae2ee7a1c 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -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))), diff --git a/src/core/manager.c b/src/core/manager.c index 02623be4bf6..66840407b5f 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -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); } diff --git a/src/core/manager.h b/src/core/manager.h index 66ad04baf54..e42ee3dd36e 100644 --- a/src/core/manager.h +++ b/src/core/manager.h @@ -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; -- 2.47.3