Date: Wed, 5 May 2021 07:24:10 GMT From: Baptiste Daroussin <bapt@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 3e1022b4eb5f - stable/12 - Make pkg(7) use environment variables specified in pkg.conf Message-ID: <202105050724.1457OAWP048518@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/12 has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=3e1022b4eb5f452a8bbcb651f3367417988e75ab commit 3e1022b4eb5f452a8bbcb651f3367417988e75ab Author: Moritz Schmitt <moritz@schmi.tt> AuthorDate: 2021-04-27 01:59:12 +0000 Commit: Baptiste Daroussin <bapt@FreeBSD.org> CommitDate: 2021-05-05 07:16:30 +0000 Make pkg(7) use environment variables specified in pkg.conf Modify /usr/sbin/pkg to use environment variables specified in pkg.conf. This allows control over underlying libraries like fetch(3), which can be configured by setting HTTP_PROXY. Differential Revision: https://reviews.freebsd.org/D29820 (cherry picked from commit e869d3c60147bbb226b5ad97d2ef73391aeebafa) --- usr.sbin/pkg/config.c | 29 +++++++++++++++++++++++++---- usr.sbin/pkg/config.h | 2 ++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/usr.sbin/pkg/config.c b/usr.sbin/pkg/config.c index e467a3c34357..80469bf2b5a5 100644 --- a/usr.sbin/pkg/config.c +++ b/usr.sbin/pkg/config.c @@ -42,6 +42,7 @@ __FBSDID("$FreeBSD$"); #include <errno.h> #include <stdbool.h> #include <unistd.h> +#include <ctype.h> #include "config.h" @@ -134,6 +135,15 @@ static struct config_entry c[] = { NULL, false, false + }, + [PKG_ENV] = { + PKG_CONFIG_OBJECT, + "PKG_ENV", + NULL, + NULL, + NULL, + false, + false, } }; @@ -205,11 +215,11 @@ static void config_parse(const ucl_object_t *obj, pkg_conf_file_t conftype) { struct sbuf *buf = sbuf_new_auto(); - const ucl_object_t *cur, *seq; - ucl_object_iter_t it = NULL, itseq = NULL; + const ucl_object_t *cur, *seq, *tmp; + ucl_object_iter_t it = NULL, itseq = NULL, it_obj = NULL; struct config_entry *temp_config; struct config_value *cv; - const char *key; + const char *key, *evkey; int i; size_t j; @@ -224,7 +234,7 @@ config_parse(const ucl_object_t *obj, pkg_conf_file_t conftype) if (conftype == CONFFILE_PKG) { for (j = 0; j < strlen(key); ++j) - sbuf_putc(buf, key[j]); + sbuf_putc(buf, toupper(key[j])); sbuf_finish(buf); } else if (conftype == CONFFILE_REPO) { if (strcasecmp(key, "url") == 0) @@ -285,6 +295,17 @@ config_parse(const ucl_object_t *obj, pkg_conf_file_t conftype) temp_config[i].value = strdup(ucl_object_toboolean(cur) ? "yes" : "no"); break; + case PKG_CONFIG_OBJECT: + if (strcmp(c[i].key, "PKG_ENV") == 0) { + while ((tmp = + ucl_iterate_object(cur, &it_obj, true))) { + evkey = ucl_object_key(tmp); + if (evkey != NULL && *evkey != '\0') { + setenv(evkey, ucl_object_tostring_forced(tmp), 1); + } + } + } + break; default: /* Normal string value. */ temp_config[i].value = strdup(ucl_object_tostring(cur)); diff --git a/usr.sbin/pkg/config.h b/usr.sbin/pkg/config.h index a63997a7a60d..b5553111c610 100644 --- a/usr.sbin/pkg/config.h +++ b/usr.sbin/pkg/config.h @@ -43,6 +43,7 @@ typedef enum { FINGERPRINTS, REPOS_DIR, PUBKEY, + PKG_ENV, CONFIG_SIZE } pkg_config_key; @@ -50,6 +51,7 @@ typedef enum { PKG_CONFIG_STRING=0, PKG_CONFIG_BOOL, PKG_CONFIG_LIST, + PKG_CONFIG_OBJECT } pkg_config_t; typedef enum {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202105050724.1457OAWP048518>