[BACK]Return to rc.shutdown CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / etc

File: [cvs.NetBSD.org] / src / etc / rc.shutdown (download)

Revision, Mon Jul 2 21:20:52 2012 UTC (7 years, 1 month ago) by jdc
Branch: netbsd-6
CVS Tags: netbsd-6-1-RELEASE, netbsd-6-1-RC4, netbsd-6-1-RC3, netbsd-6-1-RC2, netbsd-6-1-RC1, netbsd-6-1-5-RELEASE, netbsd-6-1-4-RELEASE, netbsd-6-1-3-RELEASE, netbsd-6-1-2-RELEASE, netbsd-6-1-1-RELEASE, netbsd-6-1, netbsd-6-0-RELEASE, netbsd-6-0-RC2, netbsd-6-0-RC1, netbsd-6-0-6-RELEASE, netbsd-6-0-5-RELEASE, netbsd-6-0-4-RELEASE, netbsd-6-0-3-RELEASE, netbsd-6-0-2-RELEASE, netbsd-6-0-1-RELEASE, netbsd-6-0, matt-nb6-plus-nbase, matt-nb6-plus-base, matt-nb6-plus
Changes since 1.8: +5 -3 lines

Pull up revision 1.9 (requested by jnemeth in ticket #375).

PR/46601 - Jim Bernard -- add support for rc_directories

# $NetBSD: rc.shutdown,v 2012/07/02 21:20:52 jdc Exp $
# rc.shutdown --
#	Run the scripts in /etc/rc.d with reverse rcorder.

#	System shutdown script run by shutdown(8) at system shutdown time.
#	Note that halt(8) and reboot(8) do NOT invoke this script.

export HOME=/
export PATH=/sbin:/bin:/usr/sbin:/usr/bin

. /etc/rc.subr
. /etc/rc.conf

if ! checkyesno do_rcshutdown; then
	echo "Skipping shutdown hooks."
	exit 0

stty status '^T'

#	Set shell to ignore SIGINT, but not children;
#	shell catches SIGQUIT and returns to single user.
trap : INT
trap "echo 'Shutdown interrupted.'; exit 1" QUIT

#	If requested, start a watchdog timer in the background which
#	will terminate rc.shutdown if rc.shutdown doesn't complete
#	within the specified time.
if [ -n "$rcshutdown_timeout" ]; then
	sleep $rcshutdown_timeout && (
	    _msg="$rcshutdown_timeout second watchdog timeout expired. Shutdown terminated."
	    logger -t rc.shutdown "$_msg"
	    echo "$_msg"
	    kill -KILL $$ >/dev/null 2>&1
	    ) &

#	Determine the shutdown order of the rc.d scripts,
#	and perform the operation
scripts=$(for rcd in ${rc_directories:-/etc/rc.d}; do
	test -d ${rcd} && echo ${rcd}/*; done)
files=$(rcorder -k shutdown ${rcshutdown_rcorder_flags} ${scripts})

for _rc_elem in $(reverse_list $files); do
	run_rc_script $_rc_elem stop

#	Terminate the background watchdog timer (if it is running)
if [ -n "$_rcshutdown_watchdog" ]; then
	kill -TERM $_rcshutdown_watchdog >/dev/null 2>&1

exit 0