mirror of
https://github.com/systemd/systemd.git
synced 2026-08-03 22:50:29 +00:00
build-path: allow overriding of all callout binary paths via an env var
This commit is contained in:
@@ -184,6 +184,30 @@ static int find_build_dir_binary(const char *fn, char **ret) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int find_environment_binary(const char *fn, const char **ret) {
|
||||
|
||||
/* If a path such as /usr/lib/systemd/systemd-foobar is specified, then this will check for an
|
||||
* environment variable SYSTEMD_FOOBAR_PATH and return it if set. */
|
||||
|
||||
_cleanup_free_ char *s = strdup(fn);
|
||||
if (!s)
|
||||
return -ENOMEM;
|
||||
|
||||
ascii_strupper(s);
|
||||
string_replace_char(s, '-', '_');
|
||||
|
||||
if (!strextend(&s, "_PATH"))
|
||||
return -ENOMEM;
|
||||
|
||||
const char *e;
|
||||
e = secure_getenv(s);
|
||||
if (!e)
|
||||
return -ENXIO;
|
||||
|
||||
*ret = e;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int invoke_callout_binary(const char *path, char *const argv[]) {
|
||||
int r;
|
||||
|
||||
@@ -198,6 +222,13 @@ int invoke_callout_binary(const char *path, char *const argv[]) {
|
||||
if (r == O_DIRECTORY) /* Uh? */
|
||||
return -EISDIR;
|
||||
|
||||
const char *e;
|
||||
if (find_environment_binary(fn, &e) >= 0) {
|
||||
/* If there's an explicit environment variable set for this binary, prefer it */
|
||||
execv(e, argv);
|
||||
return -errno; /* The environment variable counts, let's fail otherwise */
|
||||
}
|
||||
|
||||
_cleanup_free_ char *np = NULL;
|
||||
if (find_build_dir_binary(fn, &np) >= 0)
|
||||
execv(np, argv);
|
||||
|
||||
Reference in New Issue
Block a user