diff --git a/lib/initend.c b/lib/initend.c index 48073800..cf64a3e3 100644 --- a/lib/initend.c +++ b/lib/initend.c @@ -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,