From: Lennart Poettering Date: Tue, 20 Feb 2024 10:57:39 +0000 (+0100) Subject: build-path: allow overriding of all callout binary paths via an env var X-Git-Tag: v256-rc1~762^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=950ca1788e5cc024adbaf34fb24a87e20a510e81;p=thirdparty%2Fsystemd.git build-path: allow overriding of all callout binary paths via an env var --- diff --git a/src/basic/build-path.c b/src/basic/build-path.c index d81ed561dc9..0c43afaefdf 100644 --- a/src/basic/build-path.c +++ b/src/basic/build-path.c @@ -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);