xref: /freebsd/libexec/rc/rc.d/ldconfig (revision 6fa42b91ca3f481912af98c4d49c44507eb1b8e1)
1#!/bin/sh
2#
3#
4
5# PROVIDE: ldconfig
6# REQUIRE: FILESYSTEMS
7# BEFORE:  DAEMON
8
9. /etc/rc.subr
10
11name="ldconfig"
12desc="Configure the shared library cache"
13ldconfig_command="/sbin/ldconfig"
14start_cmd="ldconfig_start"
15stop_cmd=":"
16
17ldconfig_paths()
18{
19	local _dirs _files _ii _ldpaths _paths
20
21	_dirs="${1}"
22	_paths="${2}"
23	_ldpaths="${3}"
24
25	for _ii in ${_dirs}; do
26		if [ -d "${_ii}" ]; then
27			_files=`find ${_ii} -type f`
28			if [ -n "${_files}" ]; then
29				_paths="${_paths} `cat ${_files} | sort -u`"
30			fi
31		fi
32	done
33	for _ii in ${_paths}; do
34		if [ -r "${_ii}" ]; then
35			_ldpaths="${_ldpaths} ${_ii}"
36		fi
37	done
38
39	echo "${_ldpaths}"
40}
41
42ldconfig_start()
43{
44	local _files _ins
45
46	_ins=
47	ldconfig=${ldconfig_command}
48	checkyesno ldconfig_insecure && _ins="-i"
49	if [ -x "${ldconfig_command}" ]; then
50		_LDC=$(/libexec/ld-elf.so.1 -v | sed -n -e '/^Default lib path /s///p' | tr : ' ')
51		_LDC=$(ldconfig_paths "${ldconfig_local_dirs}" \
52		    "${ldconfig_paths} /etc/ld-elf.so.conf" "$_LDC")
53		startmsg 'ELF ldconfig path:' ${_LDC}
54		${ldconfig} -elf ${_ins} ${_LDC}
55
56		if check_kern_features compat_freebsd32; then
57			_LDC=""
58			if [ -x /libexec/ld-elf32.so.1 ]; then
59				for x in $(/libexec/ld-elf32.so.1 -v | sed -n -e '/^Default lib path /s///p' | tr : ' '); do
60					if [ -d "${x}" ]; then
61						_LDC="${_LDC} ${x}"
62					fi
63				done
64			fi
65			_LDC=$(ldconfig_paths "${ldconfig_local32_dirs}" \
66			    "${ldconfig32_paths}" "$_LDC")
67			startmsg '32-bit compatibility ldconfig path:' ${_LDC}
68			${ldconfig} -32 ${_ins} ${_LDC}
69		fi
70
71	fi
72}
73
74load_rc_config $name
75
76# doesn't make sense to run in a svcj: config setting
77ldconfig_svcj="NO"
78
79run_rc_command "$1"
80