pid1: port executor binary pinning to new build path logic

This commit is contained in:
Lennart Poettering
2024-02-21 09:25:46 +01:00
parent 84ab5d1f95
commit 2287565d46
3 changed files with 38 additions and 29 deletions
+29
View File
@@ -6,6 +6,7 @@
#include "build-path.h"
#include "errno-list.h"
#include "errno-util.h"
#include "macro.h"
#include "path-util.h"
#include "process-util.h"
@@ -236,3 +237,31 @@ int invoke_callout_binary(const char *path, char *const argv[]) {
execv(path, argv);
return -errno;
}
int pin_callout_binary(const char *path) {
int r;
assert(path);
/* Similar to invoke_callout_binary(), but pins (i.e. O_PATH opens) the binary instead of executing it. */
_cleanup_free_ char *fn = NULL;
r = path_extract_filename(path, &fn);
if (r < 0)
return r;
if (r == O_DIRECTORY) /* Uh? */
return -EISDIR;
const char *e;
if (find_environment_binary(fn, &e) >= 0)
return RET_NERRNO(open(e, O_CLOEXEC|O_PATH));
_cleanup_free_ char *np = NULL;
if (find_build_dir_binary(fn, &np) >= 0) {
r = RET_NERRNO(open(np, O_CLOEXEC|O_PATH));
if (r >= 0)
return r;
}
return RET_NERRNO(open(path, O_CLOEXEC|O_PATH));
}
+2
View File
@@ -4,3 +4,5 @@
int get_build_exec_dir(char **ret);
int invoke_callout_binary(const char *path, char *const argv[]);
int pin_callout_binary(const char *path);