From e3b4a51580fcd4a1ddf0d61feb5f325ff1de5420 Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Thu, 16 Jan 2025 14:50:42 +0100 Subject: [PATCH] pkg(7): expand VERSION_MAJOR, VERSION_MINOR, RELEASE and OSNAME Catchup with pkg(8) by expanding more variable when parsing repositories The only missing variable now is ARCH, this will have to wait for pkg 2.0 to be the lowest supported version. --- usr.sbin/pkg/config.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/usr.sbin/pkg/config.c b/usr.sbin/pkg/config.c index 2ad6c8a9375..26d7dd66b2a 100644 --- a/usr.sbin/pkg/config.c +++ b/usr.sbin/pkg/config.c @@ -477,11 +477,26 @@ read_conf_file(const char *confpath, const char *requested_repo, struct ucl_parser *p; ucl_object_t *obj = NULL; const char *abi = pkg_get_myabi(); + char *major, *minor; + struct utsname uts; + + if (uname(&uts)) + err(EXIT_FAILURE, "uname"); if (abi == NULL) errx(EXIT_FAILURE, "Failed to determine ABI"); p = ucl_parser_new(0); + asprintf(&major, "%d", __FreeBSD_version/100000); + if (major == NULL) + err(EXIT_FAILURE, "asprintf"); + asprintf(&minor, "%d", (__FreeBSD_version / 1000) % 100); + if (minor == NULL) + err(EXIT_FAILURE, "asprintf"); ucl_parser_register_variable(p, "ABI", abi); + ucl_parser_register_variable(p, "OSNAME", uts.sysname); + ucl_parser_register_variable(p, "RELEASE", major); + ucl_parser_register_variable(p, "VERSION_MAJOR", major); + ucl_parser_register_variable(p, "VERSION_MINOR", minor); if (!ucl_parser_add_file(p, confpath)) { if (errno != ENOENT) @@ -505,6 +520,8 @@ read_conf_file(const char *confpath, const char *requested_repo, ucl_object_unref(obj); ucl_parser_free(p); + free(major); + free(minor); return (0); }