From 7ca0d5403ede7308269e39f201fdd08cf5a3fe54 Mon Sep 17 00:00:00 2001 From: Scott Long Date: Sat, 14 Nov 2020 18:01:14 +0000 Subject: [PATCH] Replace hardcoded references to _PATH_LOCALBASE with calls to getlocalbase.3 Reviewed by: imp, se --- sbin/nvmecontrol/comnd.c | 2 +- sbin/nvmecontrol/comnd.h | 2 +- sbin/nvmecontrol/nvmecontrol.c | 11 +++++++++-- usr.sbin/mailwrapper/mailwrapper.c | 6 ++++-- usr.sbin/pkg/Makefile | 2 +- usr.sbin/pkg/pkg.c | 9 +++++++-- 6 files changed, 23 insertions(+), 9 deletions(-) diff --git a/sbin/nvmecontrol/comnd.c b/sbin/nvmecontrol/comnd.c index b8c9abc86844..2f0db309bf68 100644 --- a/sbin/nvmecontrol/comnd.c +++ b/sbin/nvmecontrol/comnd.c @@ -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(char *dir, cmd_load_cb_t cb, void *argp) { DIR *d; struct dirent *dent; diff --git a/sbin/nvmecontrol/comnd.h b/sbin/nvmecontrol/comnd.h index 91c97d4a873f..9dedb7a7057d 100644 --- a/sbin/nvmecontrol/comnd.h +++ b/sbin/nvmecontrol/comnd.h @@ -96,7 +96,7 @@ void cmd_register(struct cmd *, struct cmd *); int arg_parse(int argc, char * const *argv, const struct cmd *f); void arg_help(int argc, char * const *argv, const struct cmd *f); void cmd_init(void); -void cmd_load_dir(const char *dir, cmd_load_cb_t *cb, void *argp); +void cmd_load_dir(char *dir, cmd_load_cb_t *cb, void *argp); int cmd_dispatch(int argc, char *argv[], const struct cmd *); #endif /* COMND_H */ diff --git a/sbin/nvmecontrol/nvmecontrol.c b/sbin/nvmecontrol/nvmecontrol.c index 758822f2e25a..bc8e564a84dd 100644 --- a/sbin/nvmecontrol/nvmecontrol.c +++ b/sbin/nvmecontrol/nvmecontrol.c @@ -38,6 +38,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -178,11 +179,17 @@ get_nsid(int fd, char **ctrlr_str, uint32_t *nsid) int main(int argc, char *argv[]) { + char locallib[MAXPATHLEN]; + size_t len; cmd_init(); - cmd_load_dir("/lib/nvmecontrol", NULL, NULL); - cmd_load_dir(_PATH_LOCALBASE "/lib/nvmecontrol", NULL, NULL); + snprintf(locallib, MAXPATHLEN, "/lib/nvmecontrol"); + cmd_load_dir(locallib, NULL, NULL); + if ((len = getlocalbase(locallib, MAXPATHLEN)) > 0) { + strlcat(locallib, "/lib/nvmecontrol", MAXPATHLEN - len); + cmd_load_dir(locallib, NULL, NULL); + } cmd_dispatch(argc, argv, NULL); diff --git a/usr.sbin/mailwrapper/mailwrapper.c b/usr.sbin/mailwrapper/mailwrapper.c index 8a9ec220a26b..083949f266df 100644 --- a/usr.sbin/mailwrapper/mailwrapper.c +++ b/usr.sbin/mailwrapper/mailwrapper.c @@ -105,8 +105,10 @@ main(int argc, char *argv[], char *envp[]) initarg(&al); addarg(&al, argv[0]); - snprintf(localmailerconf, MAXPATHLEN, "%s/etc/mail/mailer.conf", - getenv("LOCALBASE") ? getenv("LOCALBASE") : _PATH_LOCALBASE); + if ((len = getlocalbase(localmailerconf, MAXPATHLEN)) != 0) + err(EX_OSERR, "cannot determine local path"); + + strlcat(localmailerconf, "/etc/mail/mailer.conf", MAXPATHLEN - len); mailerconf = localmailerconf; if ((config = fopen(localmailerconf, "r")) == NULL) diff --git a/usr.sbin/pkg/Makefile b/usr.sbin/pkg/Makefile index ebfb71c1699b..980faafc6b6c 100644 --- a/usr.sbin/pkg/Makefile +++ b/usr.sbin/pkg/Makefile @@ -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 diff --git a/usr.sbin/pkg/pkg.c b/usr.sbin/pkg/pkg.c index 3de789328c37..057a4236174d 100644 --- a/usr.sbin/pkg/pkg.c +++ b/usr.sbin/pkg/pkg.c @@ -43,6 +43,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -1037,6 +1038,7 @@ main(int argc, char *argv[]) { char pkgpath[MAXPATHLEN]; const char *pkgarg; + size_t len; int i; bool bootstrap_only, force, yes; @@ -1045,8 +1047,11 @@ main(int argc, char *argv[]) pkgarg = NULL; yes = false; - snprintf(pkgpath, MAXPATHLEN, "%s/sbin/pkg", - getenv("LOCALBASE") ? getenv("LOCALBASE") : _PATH_LOCALBASE); + if ((len = getlocalbase(pkgpath, MAXPATHLEN)) != 0) { + fprintf(stderr, "Cannot determine local path\n"); + exit(EXIT_FAILURE); + } + strlcat(pkgpath, "/sbin/pkg", MAXPATHLEN - len); if (argc > 1 && strcmp(argv[1], "bootstrap") == 0) { bootstrap_only = true;