lib/initend.c: allow XBPS{,_TARGET}_ARCH variables to overwrite config

This commit is contained in:
Duncan Overbruck 2021-02-04 23:27:06 +01:00
parent b26f4068b7
commit c6aaafb123
No known key found for this signature in database
GPG Key ID: 335C1D17EC3D6E35

View File

@ -43,6 +43,7 @@
int
xbps_init(struct xbps_handle *xhp)
{
struct utsname un;
const char *native_arch = NULL;
int rv = 0;
@ -88,25 +89,12 @@ xbps_init(struct xbps_handle *xhp)
if (xbps_path_clean(xhp->sysconfdir) == -1)
return ENOTSUP;
/* target architecture */
xhp->target_arch = getenv("XBPS_TARGET_ARCH");
if (xhp->target_arch && *xhp->target_arch == '\0')
xhp->target_arch = NULL;
/* native architecture */
if ((native_arch = getenv("XBPS_ARCH")) && *native_arch != '\0') {
if (xbps_strlcpy(xhp->native_arch, native_arch,
sizeof xhp->native_arch) >= sizeof xhp->native_arch)
return ENOBUFS;
} else {
struct utsname un;
if (uname(&un) == -1)
return ENOTSUP;
if (xbps_strlcpy(xhp->native_arch, un.machine,
sizeof xhp->native_arch) >= sizeof xhp->native_arch)
return ENOBUFS;
}
assert(*xhp->native_arch);
/* set default native architecture before parsing configuration file */
if (uname(&un) == -1)
return ENOTSUP;
if (xbps_strlcpy(xhp->native_arch, un.machine,
sizeof xhp->native_arch) >= sizeof xhp->native_arch)
return ENOBUFS;
xbps_fetch_set_cache_connection(XBPS_FETCH_CACHECONN, XBPS_FETCH_CACHECONN_HOST);
@ -114,6 +102,19 @@ xbps_init(struct xbps_handle *xhp)
if ((rv = xbps_conf_init(xhp)) != 0)
return rv;
/* target arch only through env var */
xhp->target_arch = getenv("XBPS_TARGET_ARCH");
if (xhp->target_arch && *xhp->target_arch == '\0')
xhp->target_arch = NULL;
/* allow to overwrite uname(3) and conf file with env variable */
if ((native_arch = getenv("XBPS_ARCH")) && *native_arch != '\0') {
if (xbps_strlcpy(xhp->native_arch, native_arch,
sizeof xhp->native_arch) >= sizeof xhp->native_arch)
return ENOBUFS;
}
assert(*xhp->native_arch);
/* Set cachedir */
if (xhp->cachedir[0] == '\0') {
if (xbps_path_join(xhp->cachedir, sizeof xhp->cachedir,