From 9a30f13300516f1cdf3c0f791c2801285dc2e1e4 Mon Sep 17 00:00:00 2001 From: Duncan Overbruck Date: Thu, 4 Feb 2021 23:35:48 +0100 Subject: [PATCH] lib/initend.c: only use uname(3) if native_arch was not set if the configuration file or the env variable is used we can skip uname(3). --- lib/initend.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/initend.c b/lib/initend.c index cf64a3e3..4ebe304e 100644 --- a/lib/initend.c +++ b/lib/initend.c @@ -43,7 +43,6 @@ int xbps_init(struct xbps_handle *xhp) { - struct utsname un; const char *native_arch = NULL; int rv = 0; @@ -89,13 +88,6 @@ xbps_init(struct xbps_handle *xhp) if (xbps_path_clean(xhp->sysconfdir) == -1) return ENOTSUP; - /* 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); /* process xbps.d directories */ @@ -113,6 +105,15 @@ xbps_init(struct xbps_handle *xhp) sizeof xhp->native_arch) >= sizeof xhp->native_arch) return ENOBUFS; } + + if (*xhp->native_arch == '\0') { + 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 cachedir */