#! /bin/sh
#
# Copyright (c) 2001-2002 SuSE Linux AG, Nuernberg, Germany.
# All rights reserved.
#
# /etc/init.d/boot.ldconfig
#
### BEGIN INIT INFO
# Provides:          boot.ldconfig
# Required-Start:    boot.clock
# Should-Start:      boot.crypto boot.swap
# Required-Stop:
# Default-Start:     B
# Default-Stop:
# Description:       run ldconfig if needed
### END INIT INFO

. /etc/rc.status
. /etc/sysconfig/clock

rc_reset

case "$1" in
  start|restart|stop)
	#
	# Let ld.so rebuild its cache.
	# But do some tests before if it is really needed
	LDCONFIG_NEEDED=false
	test -s /etc/ld.so.cache || LDCONFIG_NEEDED=true
	test "$run_ldconfig" = true && LDCONFIG_NEEDED=true
	test -x /usr/bin/find -a "$LDCONFIG_NEEDED" = false && {
	    for DUMMY in `/usr/bin/find /etc/ld.so.cache -mtime +30` ; do
		LDCONFIG_NEEDED=true
	    done
	}
	LIBDIRS="/lib /usr/lib /usr/local/lib"
	test -s /etc/ld.so.conf && {
	    for DIR in `cat /etc/ld.so.conf` ; do
		case $DIR in
		    /*)
			test -d "$DIR" && LIBDIRS="$LIBDIRS $DIR"
			;;
		esac
	    done
	}
	for DIR in $LIBDIRS ; do
	    test $DIR -nt /etc/ld.so.cache && {
	        LDCONFIG_NEEDED=true
	        break
	    }
	done

	test -x /sbin/ldconfig -a "$LDCONFIG_NEEDED" = true && {
	    echo -n "Setting up linker cache (/etc/ld.so.cache) using ldconfig"
	    { /sbin/ldconfig -X 2>/dev/null || \
	        { echo ; echo -e "ldconfig $rc_failed" ; } ; } &
	    rc_status -v -r
	}


	;;
    status)
	rc_failed 4
	rc_status -v
	;;
    *)
	echo "Usage: $0 {start|stop|status|restart}"
	exit 1
	;;
esac

rc_exit

