diff options
author | Scott Long <scottl@FreeBSD.org> | 2020-11-14 18:01:14 +0000 |
---|---|---|
committer | Scott Long <scottl@FreeBSD.org> | 2020-11-14 18:01:14 +0000 |
commit | 7ca0d5403ede7308269e39f201fdd08cf5a3fe54 (patch) | |
tree | adb93742f119551a2e682dca15a0013367b5da04 | |
parent | 98b76d2227cb9b951cc6f006e2c78f243344f1bc (diff) | |
download | src-7ca0d5403ede7308269e39f201fdd08cf5a3fe54.tar.gz src-7ca0d5403ede7308269e39f201fdd08cf5a3fe54.zip |
Replace hardcoded references to _PATH_LOCALBASE with calls to getlocalbase.3
Reviewed by: imp, se
Notes
Notes:
svn path=/head/; revision=367687
-rw-r--r-- | sbin/nvmecontrol/comnd.c | 2 | ||||
-rw-r--r-- | sbin/nvmecontrol/comnd.h | 2 | ||||
-rw-r--r-- | sbin/nvmecontrol/nvmecontrol.c | 11 | ||||
-rw-r--r-- | usr.sbin/mailwrapper/mailwrapper.c | 6 | ||||
-rw-r--r-- | usr.sbin/pkg/Makefile | 2 | ||||
-rw-r--r-- | 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 @@ bad_arg: * 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 <err.h> #include <errno.h> #include <fcntl.h> +#include <libutil.h> #include <paths.h> #include <stdbool.h> #include <stddef.h> @@ -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 <bsd.prog.mk> 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 <errno.h> #include <fcntl.h> #include <fetch.h> +#include <libutil.h> #include <paths.h> #include <stdbool.h> #include <stdlib.h> @@ -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; |