git: 0bd3f757f9cf - stable/14 - pkg(7): expand VERSION_MAJOR, VERSION_MINOR, RELEASE and OSNAME

From: Baptiste Daroussin <bapt_at_FreeBSD.org>
Date: Thu, 06 Mar 2025 15:40:01 UTC
The branch stable/14 has been updated by bapt:

URL: https://cgit.FreeBSD.org/src/commit/?id=0bd3f757f9cff089e07688f598d70531f5ee32e3

commit 0bd3f757f9cff089e07688f598d70531f5ee32e3
Author:     Baptiste Daroussin <bapt@FreeBSD.org>
AuthorDate: 2025-01-16 13:50:42 +0000
Commit:     Baptiste Daroussin <bapt@FreeBSD.org>
CommitDate: 2025-03-06 15:39:14 +0000

    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.
    
    (cherry picked from commit e3b4a51580fcd4a1ddf0d61feb5f325ff1de5420)
---
 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 e02da1461294..16f7598fc745 100644
--- a/usr.sbin/pkg/config.c
+++ b/usr.sbin/pkg/config.c
@@ -478,11 +478,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, "Fail do 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)
@@ -506,6 +521,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);
 }