if ! checkyesno do_rcshutdown; then
echo "Skipping shutdown hooks."
exit 0
fi
_rcshutdown_action="$1"
set --
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.
#
_rcshutdown_watchdog=
if [ -n "$rcshutdown_timeout" ]; then
sleep $rcshutdown_timeout && (
_msg="$rcshutdown_timeout second watchdog timeout expired. Shutdown terminated."
logger -t rc.shutdown "$_msg"
echo "$_msg"
date
kill -KILL $$ >/dev/null 2>&1
) &
_rcshutdown_watchdog=$!
fi
# 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
done
#
# Run final local handlers (if any exist)
#
if [ -r /etc/rc.shutdown.final ]; then
set -- "$_rcshutdown_action"
. /etc/rc.shutdown.final
fi
# Terminate the background watchdog timer (if it is running)
#
if [ -n "$_rcshutdown_watchdog" ]; then
kill -TERM $_rcshutdown_watchdog >/dev/null 2>&1
fi