Make use of the getlocalbase() function for run-time adjustment of the

local software base directory, as committed in SVN rev. 367813.

The pkg and mailwrapper programs used the LOCALBASE environment variable
for this purpose and this functionality is preserved by getlocalbase().

After this change, the value of the user.localbase sysctl variable is used
if present (and not overridden in the environment).

The nvmecontrol program gains support of a dynamic path to its plugin
directory with this update.

Differential Revision:	https://reviews.freebsd.org/D27237
This commit is contained in:
Stefan Eßer 2020-11-18 20:00:55 +00:00
parent 991f6e7534
commit 56d11d4a37
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=367816
6 changed files with 12 additions and 10 deletions

View File

@ -287,7 +287,7 @@ arg_parse(int argc, char * const * argv, const struct cmd *f)
* Loads all the .so's from the specified directory.
*/
void
cmd_load_dir(const char *dir __unused, cmd_load_cb_t cb __unused, void *argp __unused)
cmd_load_dir(const char *dir, cmd_load_cb_t cb, void *argp)
{
DIR *d;
struct dirent *dent;

View File

@ -38,6 +38,7 @@ __FBSDID("$FreeBSD$");
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <libutil.h>
#include <paths.h>
#include <stdbool.h>
#include <stddef.h>
@ -178,11 +179,13 @@ get_nsid(int fd, char **ctrlr_str, uint32_t *nsid)
int
main(int argc, char *argv[])
{
static char dir[MAXPATHLEN];
cmd_init();
cmd_load_dir("/lib/nvmecontrol", NULL, NULL);
cmd_load_dir(_PATH_LOCALBASE "/lib/nvmecontrol", NULL, NULL);
snprintf(dir, MAXPATHLEN, "%s/lib/nvmecontrol", getlocalbase());
cmd_load_dir(dir, NULL, NULL);
cmd_dispatch(argc, argv, NULL);

View File

@ -106,7 +106,7 @@ main(int argc, char *argv[], char *envp[])
addarg(&al, argv[0]);
snprintf(localmailerconf, MAXPATHLEN, "%s/etc/mail/mailer.conf",
getenv("LOCALBASE") ? getenv("LOCALBASE") : _PATH_LOCALBASE);
getlocalbase());
mailerconf = localmailerconf;
if ((config = fopen(localmailerconf, "r")) == NULL)

View File

@ -25,6 +25,6 @@ MAN= pkg.7
CFLAGS+=-I${SRCTOP}/contrib/libucl/include
.PATH: ${SRCTOP}/contrib/libucl/include
LIBADD= archive fetch ucl sbuf crypto ssl
LIBADD= archive fetch ucl sbuf crypto ssl util
.include <bsd.prog.mk>

View File

@ -40,6 +40,7 @@ __FBSDID("$FreeBSD$");
#include <ucl.h>
#include <err.h>
#include <errno.h>
#include <libutil.h>
#include <paths.h>
#include <stdbool.h>
#include <unistd.h>
@ -455,9 +456,8 @@ config_init(void)
}
/* Read LOCALBASE/etc/pkg.conf first. */
localbase = getenv("LOCALBASE") ? getenv("LOCALBASE") : _PATH_LOCALBASE;
snprintf(confpath, sizeof(confpath), "%s/etc/pkg.conf",
localbase);
localbase = getlocalbase();
snprintf(confpath, sizeof(confpath), "%s/etc/pkg.conf", localbase);
if (access(confpath, F_OK) == 0 && read_conf_file(confpath,
CONFFILE_PKG))

View File

@ -43,12 +43,12 @@ __FBSDID("$FreeBSD$");
#include <errno.h>
#include <fcntl.h>
#include <fetch.h>
#include <libutil.h>
#include <paths.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <ucl.h>
#include <openssl/err.h>
@ -1045,8 +1045,7 @@ main(int argc, char *argv[])
pkgarg = NULL;
yes = false;
snprintf(pkgpath, MAXPATHLEN, "%s/sbin/pkg",
getenv("LOCALBASE") ? getenv("LOCALBASE") : _PATH_LOCALBASE);
snprintf(pkgpath, MAXPATHLEN, "%s/sbin/pkg", getlocalbase());
if (argc > 1 && strcmp(argv[1], "bootstrap") == 0) {
bootstrap_only = true;