pid1: port executor binary pinning to new build path logic
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user