git: e3b4a51580fc - main - pkg(7): expand VERSION_MAJOR, VERSION_MINOR, RELEASE and OSNAME
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 16 Jan 2025 13:51:53 UTC
The branch main has been updated by bapt:
URL: https://cgit.FreeBSD.org/src/commit/?id=e3b4a51580fcd4a1ddf0d61feb5f325ff1de5420
commit e3b4a51580fcd4a1ddf0d61feb5f325ff1de5420
Author: Baptiste Daroussin <bapt@FreeBSD.org>
AuthorDate: 2025-01-16 13:50:42 +0000
Commit: Baptiste Daroussin <bapt@FreeBSD.org>
CommitDate: 2025-01-16 13:50:42 +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.
---
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 2ad6c8a93756..26d7dd66b2a4 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);
}