From owner-dev-commits-src-branches@freebsd.org Wed May 5 07:24:00 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 20B3C632CE8; Wed, 5 May 2021 07:24:00 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4FZp9X0DTPz3G3K; Wed, 5 May 2021 07:24:00 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id E95EE20A47; Wed, 5 May 2021 07:23:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1457Nxce048306; Wed, 5 May 2021 07:23:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1457NxGs048305; Wed, 5 May 2021 07:23:59 GMT (envelope-from git) Date: Wed, 5 May 2021 07:23:59 GMT Message-Id: <202105050723.1457NxGs048305@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Baptiste Daroussin Subject: git: 3c5d1c587c59 - stable/13 - Make pkg(7) use environment variables specified in pkg.conf MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bapt X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 3c5d1c587c59e58a3b9f85b93ecee7156c219972 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 05 May 2021 07:24:00 -0000 The branch stable/13 has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=3c5d1c587c59e58a3b9f85b93ecee7156c219972 commit 3c5d1c587c59e58a3b9f85b93ecee7156c219972 Author: Moritz Schmitt AuthorDate: 2021-04-27 01:59:12 +0000 Commit: Baptiste Daroussin CommitDate: 2021-05-05 07:17:14 +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 3a5434639d6d..2bcfd9c405f3 100644 --- a/usr.sbin/pkg/config.c +++ b/usr.sbin/pkg/config.c @@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include "config.h" @@ -136,6 +137,15 @@ static struct config_entry c[] = { NULL, false, false + }, + [PKG_ENV] = { + PKG_CONFIG_OBJECT, + "PKG_ENV", + NULL, + NULL, + NULL, + false, + false, } }; @@ -207,11 +217,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; @@ -226,7 +236,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) @@ -287,6 +297,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 afcd728abd92..87efd3c29e94 100644 --- a/usr.sbin/pkg/config.h +++ b/usr.sbin/pkg/config.h @@ -44,6 +44,7 @@ typedef enum { FINGERPRINTS, REPOS_DIR, PUBKEY, + PKG_ENV, CONFIG_SIZE } pkg_config_key; @@ -51,6 +52,7 @@ typedef enum { PKG_CONFIG_STRING=0, PKG_CONFIG_BOOL, PKG_CONFIG_LIST, + PKG_CONFIG_OBJECT } pkg_config_t; typedef enum {