Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 27 Aug 2024 21:26:37 GMT
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: ee104259c72c - stable/14 - rc.d/ldconfig: Compute ldconfig paths in a function
Message-ID:  <202408272126.47RLQbYT034387@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/14 has been updated by jhb:

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

commit ee104259c72c24ca2495f7d7c4aac2672c010478
Author:     Konrad Witaszczyk <def@FreeBSD.org>
AuthorDate: 2024-04-12 21:34:59 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2024-08-27 18:15:48 +0000

    rc.d/ldconfig: Compute ldconfig paths in a function
    
    Move logic that computes paths passed to ldconfig(8) to a
    ldconfig_paths() function that can be called for multiple ABIs.
    
    Reviewed by:    olce, kib
    Obtained from:  CheriBSD
    Differential Revision:  https://reviews.freebsd.org/D44751
    
    (cherry picked from commit e6e38bc522e29de6299536b547bf11dab11e9679)
---
 libexec/rc/rc.d/ldconfig | 55 +++++++++++++++++++++++++-----------------------
 1 file changed, 29 insertions(+), 26 deletions(-)

diff --git a/libexec/rc/rc.d/ldconfig b/libexec/rc/rc.d/ldconfig
index 5c404a823dbb..fd54b2d3444e 100755
--- a/libexec/rc/rc.d/ldconfig
+++ b/libexec/rc/rc.d/ldconfig
@@ -14,6 +14,31 @@ ldconfig_command="/sbin/ldconfig"
 start_cmd="ldconfig_start"
 stop_cmd=":"
 
+ldconfig_paths()
+{
+	local _dirs _files _ii _ldpaths _paths
+
+	_dirs="${1}"
+	_paths="${2}"
+	_ldpaths="${3}"
+
+	for _ii in ${_dirs}; do
+		if [ -d "${_ii}" ]; then
+			_files=`find ${_ii} -type f`
+			if [ -n "${_files}" ]; then
+				_paths="${_paths} `cat ${_files} | sort -u`"
+			fi
+		fi
+	done
+	for _ii in ${_paths}; do
+		if [ -r "${_ii}" ]; then
+			_ldpaths="${_ldpaths} ${_ii}"
+		fi
+	done
+
+	echo "${_ldpaths}"
+}
+
 ldconfig_start()
 {
 	local _files _ins
@@ -23,31 +48,12 @@ ldconfig_start()
 	checkyesno ldconfig_insecure && _ins="-i"
 	if [ -x "${ldconfig_command}" ]; then
 		_LDC=$(/libexec/ld-elf.so.1 -v | sed -n -e '/^Default lib path /s///p' | tr : ' ')
-		for i in ${ldconfig_local_dirs}; do
-			if [ -d "${i}" ]; then
-				_files=`find ${i} -type f`
-				if [ -n "${_files}" ]; then
-					ldconfig_paths="${ldconfig_paths} `cat ${_files} | sort -u`"
-				fi
-			fi
-		done
-		for i in ${ldconfig_paths} /etc/ld-elf.so.conf; do
-			if [ -r "${i}" ]; then
-				_LDC="${_LDC} ${i}"
-			fi
-		done
+		_LDC=$(ldconfig_paths "${ldconfig_local_dirs}" \
+		    "${ldconfig_paths} /etc/ld-elf.so.conf" "$_LDC")
 		startmsg 'ELF ldconfig path:' ${_LDC}
 		${ldconfig} -elf ${_ins} ${_LDC}
 
 		if check_kern_features compat_freebsd32; then
-			for i in ${ldconfig_local32_dirs}; do
-				if [ -d "${i}" ]; then
-					_files=`find ${i} -type f`
-					if [ -n "${_files}" ]; then
-						ldconfig32_paths="${ldconfig32_paths} `cat ${_files} | sort -u`"
-					fi
-				fi
-			done
 			_LDC=""
 			if [ -x /libexec/ld-elf32.so.1 ]; then
 				for x in $(/libexec/ld-elf32.so.1 -v | sed -n -e '/^Default lib path /s///p' | tr : ' '); do
@@ -56,11 +62,8 @@ ldconfig_start()
 					fi
 				done
 			fi
-			for i in ${ldconfig32_paths}; do
-				if [ -r "${i}" ]; then
-					_LDC="${_LDC} ${i}"
-				fi
-			done
+			_LDC=$(ldconfig_paths "${ldconfig_local32_dirs}" \
+			    "${ldconfig32_paths}" "$_LDC")
 			startmsg '32-bit compatibility ldconfig path:' ${_LDC}
 			${ldconfig} -32 ${_ins} ${_LDC}
 		fi



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202408272126.47RLQbYT034387>