156083Skris#!/bin/sh 256083Skris# 356083Skris# $NetBSD: rc.shutdown,v 1.8 2002/05/19 01:01:33 lukem Exp $ 456083Skris# 556083Skris# rc.shutdown -- 656083Skris# Run the scripts in /etc/rc.d with reverse rcorder. 756083Skris 856083Skris# System shutdown script run by shutdown(8) at system shutdown time. 956083Skris# Note that halt(8) and reboot(8) do NOT invoke this script. 1056083Skris 1156083Skrisexport HOME=/ 1256083Skrisexport PATH=/sbin:/bin:/usr/sbin:/usr/bin 1356083Skris 1456083Skris. /etc/rc.subr 1556083Skris. /etc/rc.conf 1656083Skris 1756083Skrisif ! checkyesno do_rcshutdown; then 1856083Skris echo "Skipping shutdown hooks." 1956083Skris exit 0 2056083Skrisfi 2156083Skris 2256083Skrisstty status '^T' 2356083Skris 2456083Skris# Set shell to ignore SIGINT, but not children; 2556083Skris# shell catches SIGQUIT and returns to single user. 2656083Skris# 2756083Skristrap : INT 2856083Skristrap "echo 'Shutdown interrupted.'; exit 1" QUIT 2956083Skris 3056083Skris# If requested, start a watchdog timer in the background which 3156083Skris# will terminate rc.shutdown if rc.shutdown doesn't complete 3256083Skris# within the specified time. 3356083Skris# 3456083Skris_rcshutdown_watchdog= 3556083Skrisif [ -n "$rcshutdown_timeout" ]; then 3656083Skris sleep $rcshutdown_timeout && ( 3756083Skris _msg="$rcshutdown_timeout second watchdog timeout expired. Shutdown terminated." 3856083Skris logger -t rc.shutdown "$_msg" 3956083Skris echo "$_msg" 4056083Skris date 4156083Skris kill -KILL $$ >/dev/null 2>&1 4256083Skris ) & 4356083Skris _rcshutdown_watchdog=$! 4456083Skrisfi 4556083Skris 4656083Skris 4756083Skris# Determine the shutdown order of the rc.d scripts, 4856083Skris# and perform the operation 4956083Skris# 5056083Skrisscripts=$(for rcd in ${rc_directories:-/etc/rc.d}; do 5156083Skris test -d ${rcd} && echo ${rcd}/*; done) 5256083Skrisfiles=$(rcorder -k shutdown ${rcshutdown_rcorder_flags} ${scripts}) 5356083Skris 5456083Skrisfor _rc_elem in $(reverse_list $files); do 5556083Skris run_rc_script $_rc_elem stop 5656083Skrisdone 5756083Skris 5856083Skris 5956083Skris# Terminate the background watchdog timer (if it is running) 6056083Skris# 6156083Skrisif [ -n "$_rcshutdown_watchdog" ]; then 6256083Skris kill -TERM $_rcshutdown_watchdog >/dev/null 2>&1 6356083Skrisfi 6456083Skris 6556083Skrisdate 66109998Smarkmexit 0 67109998Smarkm