git: c8b89c11a118 - main - periodic: set _localbase for periodic scripts from within periodic.conf

From: Juraj Lutter <otis_at_FreeBSD.org>
Date: Tue, 21 Jan 2025 21:15:31 UTC
The branch main has been updated by otis:

URL: https://cgit.FreeBSD.org/src/commit/?id=c8b89c11a1181e900acb638cfde7a55e92553175

commit c8b89c11a1181e900acb638cfde7a55e92553175
Author:     Juraj Lutter <otis@FreeBSD.org>
AuthorDate: 2024-11-08 13:38:19 +0000
Commit:     Juraj Lutter <otis@FreeBSD.org>
CommitDate: 2025-01-21 21:14:41 +0000

    periodic: set _localbase for periodic scripts from within periodic.conf
    
    Set _localbase variable from within /etc/defaults/periodic.conf
    for use by periodic scripts.
    
    This fixes e5d7100c09, no other functional changes intended.
    
    Reported by:            gahr, otis
    Reviewed by:            markj, gahr
    MFC after:              2 weeks
    Differential Revision:  https://reviews.freebsd.org/D47486
---
 usr.sbin/periodic/periodic.conf |  9 +++++++++
 usr.sbin/periodic/periodic.sh   | 12 ++++--------
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/usr.sbin/periodic/periodic.conf b/usr.sbin/periodic/periodic.conf
index 3bb34d827564..7066c7b49fd1 100644
--- a/usr.sbin/periodic/periodic.conf
+++ b/usr.sbin/periodic/periodic.conf
@@ -15,6 +15,15 @@
 #
 #
 
+_set_localbase() {
+	_localbase=`/sbin/sysctl -n user.localbase 2> /dev/null`
+	# Set default value of _localbase if not previously set
+	: ${_localbase:="/usr/local"}
+}
+
+# Set _localbase with fallback to /usr/local
+_set_localbase
+
 # What files override these defaults ?
 periodic_conf_files="/etc/periodic.conf /etc/periodic.conf.local ${_localbase}/etc/periodic.conf"
 
diff --git a/usr.sbin/periodic/periodic.sh b/usr.sbin/periodic/periodic.sh
index 09727a840eff..a310f04864da 100644
--- a/usr.sbin/periodic/periodic.sh
+++ b/usr.sbin/periodic/periodic.sh
@@ -29,14 +29,6 @@ if [ $# -lt 1 ] ; then
     usage
 fi
 
-_localbase=`/sbin/sysctl -n user.localbase 2> /dev/null`
-# Set default value of _localbase if not previously set
-: ${_localbase:="/usr/local"}
-
-# Use a deterministic path to match the preset from /etc/crontab in case
-# periodic is run interactively.
-export PATH=/sbin:/bin:/usr/sbin:/usr/bin:${_localbase}/sbin:${_localbase}/bin
-
 # If possible, check the global system configuration file,
 # to see if there are additional dirs to check
 if [ -r /etc/defaults/periodic.conf ]; then
@@ -44,6 +36,10 @@ if [ -r /etc/defaults/periodic.conf ]; then
     source_periodic_confs
 fi
 
+# Use a deterministic path to match the preset from /etc/crontab in case
+# periodic is run interactively.
+export PATH=/sbin:/bin:/usr/sbin:/usr/bin:${_localbase}/sbin:${_localbase}/bin
+
 host=`hostname`
 export host