Replace hardcoded references to _PATH_LOCALBASE with calls to getlocalbase.3

Reviewed by:	imp, se
This commit is contained in:
Scott Long 2020-11-14 18:01:14 +00:00
parent 98b76d2227
commit 7ca0d5403e
6 changed files with 23 additions and 9 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(char *dir, cmd_load_cb_t cb, void *argp)
{
DIR *d;
struct dirent *dent;

View File

@ -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 */

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,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);

View File

@ -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)

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

@ -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;