git: 3a46fe226193 - main - getlocalbase: Make default path actually configurable
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 11 Jul 2023 20:49:49 UTC
The branch main has been updated by jrtc27:
URL: https://cgit.FreeBSD.org/src/commit/?id=3a46fe226193dde1270ebb08d2066a77ae12d7e9
commit 3a46fe226193dde1270ebb08d2066a77ae12d7e9
Author: Jessica Clarke <jrtc27@FreeBSD.org>
AuthorDate: 2023-07-11 20:49:22 +0000
Commit: Jessica Clarke <jrtc27@FreeBSD.org>
CommitDate: 2023-07-11 20:49:22 +0000
getlocalbase: Make default path actually configurable
We include paths.h in getlocalbase.c, which defines _PATH_LOCALBASE.
This will override a definition on the command line, meaning it is
impossible to override like how the manpage says you can, and it means
the code to provide a fallback default is dead as the macro is always
defined.
Instead, introduce a new LOCALBASE_PATH macro like LOCALBASE_CTL_LEN
that can be set on the command line and will default to the system's
existing _PATH_LOCALBASE to avoid duplicating the default here.
Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D40975
---
lib/libutil/getlocalbase.3 | 8 ++++----
lib/libutil/getlocalbase.c | 10 +++++-----
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/lib/libutil/getlocalbase.3 b/lib/libutil/getlocalbase.3
index e7be3f1809ef..06216b8b48a2 100644
--- a/lib/libutil/getlocalbase.3
+++ b/lib/libutil/getlocalbase.3
@@ -27,7 +27,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd November 25, 2020
+.Dd July 11, 2023
.Dt GETLOCALBASE 3
.Os
.Sh NAME
@@ -53,10 +53,10 @@ If that does not exist then the
.Va user.localbase
sysctl is checked.
If that also does not exist then the value of the
-.Dv _PATH_LOCALBASE
+.Dv LOCALBASE_PATH
compile-time variable is used.
-If that is undefined then the default of
-.Pa /usr/local
+If that is undefined then the system default,
+.Pa _PATH_LOCALBASE
is used.
.Pp
The contents of the string returned by the
diff --git a/lib/libutil/getlocalbase.c b/lib/libutil/getlocalbase.c
index a737d8c5c253..c19cb95212dd 100644
--- a/lib/libutil/getlocalbase.c
+++ b/lib/libutil/getlocalbase.c
@@ -37,8 +37,8 @@ __FBSDID("$FreeBSD$");
#include <libutil.h>
#include <unistd.h>
-#ifndef _PATH_LOCALBASE
-#define _PATH_LOCALBASE "/usr/local"
+#ifndef LOCALBASE_PATH
+#define LOCALBASE_PATH _PATH_LOCALBASE
#endif
#ifndef LOCALBASE_CTL_LEN
@@ -73,17 +73,17 @@ getlocalbase(void)
#if LOCALBASE_CTL_LEN > 0
if (sysctl(localbase_oid, 2, localpath, &localpathlen, NULL, 0) != 0) {
if (errno != ENOMEM)
- localbase = _PATH_LOCALBASE;
+ localbase = LOCALBASE_PATH;
else
localbase = ILLEGAL_PREFIX;
} else {
if (localpath[0] != '\0')
localbase = localpath;
else
- localbase = _PATH_LOCALBASE;
+ localbase = LOCALBASE_PATH;
}
#else
- localbase = _PATH_LOCALBASE;
+ localbase = LOCALBASE_PATH;
#endif
return (localbase);