aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Baldwin <jhb@FreeBSD.org>2023-11-16 00:53:53 +0000
committerJohn Baldwin <jhb@FreeBSD.org>2023-11-16 00:53:53 +0000
commitfd9ae9ac04edf9acef4a2ffbf663698a2b8e7ced (patch)
tree1bfea1032581a6e8dc5bb948fc0aea873fb99fdd
parent5972ffde919ab65ba29d4d51ccf735da18d52719 (diff)
-rw-r--r--usr.sbin/pkg/config.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/usr.sbin/pkg/config.c b/usr.sbin/pkg/config.c
index a2b005eca835..ce3a11cf8c81 100644
--- a/usr.sbin/pkg/config.c
+++ b/usr.sbin/pkg/config.c
@@ -144,32 +144,35 @@ static struct config_entry c[] = {
}
};
-static int
-pkg_get_myabi(char *dest, size_t sz)
+static char *
+pkg_get_myabi(void)
{
struct utsname uts;
char machine_arch[255];
+ char *abi;
size_t len;
int error;
error = uname(&uts);
if (error)
- return (errno);
+ return (NULL);
len = sizeof(machine_arch);
error = sysctlbyname("hw.machine_arch", machine_arch, &len, NULL, 0);
if (error)
- return (errno);
+ return (NULL);
machine_arch[len] = '\0';
/*
* Use __FreeBSD_version rather than kernel version (uts.release) for
* use in jails. This is equivalent to the value of uname -U.
*/
- snprintf(dest, sz, "%s:%d:%s", uts.sysname, __FreeBSD_version/100000,
+ error = asprintf(&abi, "%s:%d:%s", uts.sysname, __FreeBSD_version/100000,
machine_arch);
+ if (error < 0)
+ return (NULL);
- return (error);
+ return (abi);
}
static void
@@ -453,10 +456,9 @@ config_init(const char *requested_repo)
char *val;
int i;
const char *localbase;
- char *env_list_item;
+ char *abi, *env_list_item;
char confpath[MAXPATHLEN];
struct config_value *cv;
- char abi[BUFSIZ];
for (i = 0; i < CONFIG_SIZE; i++) {
val = getenv(c[i].key);
@@ -512,7 +514,8 @@ config_init(const char *requested_repo)
finalize:
if (c[ABI].val == NULL && c[ABI].value == NULL) {
- if (pkg_get_myabi(abi, BUFSIZ) != 0)
+ abi = pkg_get_myabi();
+ if (abi == NULL)
errx(EXIT_FAILURE, "Failed to determine the system "
"ABI");
c[ABI].val = abi;