core: also stash executor path in Manager

Prompted by b58c240312

Let's not query it over and over again in exec_spawn().
This commit is contained in:
Mike Yuan
2025-04-05 02:33:00 +09:00
committed by Yu Watanabe
parent c3c905c6c1
commit b157a7e613
3 changed files with 7 additions and 13 deletions
+3 -6
View 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))),
+3 -7
View 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);
}
+1
View 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;