Module Name: src
Committed By: martin
Date: Sat Dec 7 18:45:20 UTC 2024
Modified Files:
src/distrib/sets/lists/man: mi
src/distrib/sets/lists/manhtml: mi
src/etc: rc.shutdown
src/share/man/man8: Makefile rc.8
Log Message:
Now that shutdown(8) provides info why we are shutting down to the
shutdown scripts, add an optional local hook /etc/rc.shutdown.final
called last in the shutdown sequence and passed the reason.
This allows for easy local integration of special UPS commands before
we power down (e.g. to restart the UPS after some delay in case
utility power is restored too early and the machine has already powered
down and will only restart when it's power input is restored after being
off for a few seconds)
To generate a diff of this commit:
cvs rdiff -u -r1.1790 -r1.1791 src/distrib/sets/lists/man/mi
cvs rdiff -u -r1.12 -r1.13 src/distrib/sets/lists/manhtml/mi
cvs rdiff -u -r1.9 -r1.10 src/etc/rc.shutdown
cvs rdiff -u -r1.111 -r1.112 src/share/man/man8/Makefile
cvs rdiff -u -r1.39 -r1.40 src/share/man/man8/rc.8
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/distrib/sets/lists/man/mi
diff -u src/distrib/sets/lists/man/mi:1.1790 src/distrib/sets/lists/man/mi:1.1791
--- src/distrib/sets/lists/man/mi:1.1790 Mon Nov 4 20:43:38 2024
+++ src/distrib/sets/lists/man/mi Sat Dec 7 18:45:20 2024
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1790 2024/11/04 20:43:38 brad Exp $
+# $NetBSD: mi,v 1.1791 2024/12/07 18:45:20 martin Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
./etc/mtree/set.man man-sys-root
@@ -3283,6 +3283,7 @@
./usr/share/man/cat8/rc.d.0 man-rc-catman .cat
./usr/share/man/cat8/rc.local.0 man-rc-catman .cat
./usr/share/man/cat8/rc.shutdown.0 man-rc-catman .cat
+./usr/share/man/cat8/rc.shutdown.final.0 man-rc-catman .cat
./usr/share/man/cat8/rc.subr.0 man-rc-catman .cat
./usr/share/man/cat8/rcorder.0 man-sysutil-catman .cat
./usr/share/man/cat8/rdate.0 man-netutil-catman .cat
@@ -6850,6 +6851,7 @@
./usr/share/man/man8/rc.d.8 man-rc-man .man
./usr/share/man/man8/rc.local.8 man-rc-man .man
./usr/share/man/man8/rc.shutdown.8 man-rc-man .man
+./usr/share/man/man8/rc.shutdown.final.8 man-rc-man .man
./usr/share/man/man8/rc.subr.8 man-rc-man .man
./usr/share/man/man8/rcorder.8 man-sysutil-man .man
./usr/share/man/man8/rdate.8 man-netutil-man .man
Index: src/distrib/sets/lists/manhtml/mi
diff -u src/distrib/sets/lists/manhtml/mi:1.12 src/distrib/sets/lists/manhtml/mi:1.13
--- src/distrib/sets/lists/manhtml/mi:1.12 Mon Nov 4 20:43:39 2024
+++ src/distrib/sets/lists/manhtml/mi Sat Dec 7 18:45:20 2024
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.12 2024/11/04 20:43:39 brad Exp $
+# $NetBSD: mi,v 1.13 2024/12/07 18:45:20 martin Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -2915,6 +2915,7 @@
./usr/share/man/html8/rc.html man-rc-htmlman html
./usr/share/man/html8/rc.local.html man-rc-htmlman html
./usr/share/man/html8/rc.shutdown.html man-rc-htmlman html
+./usr/share/man/html8/rc.shutdown.final.html man-rc-htmlman html
./usr/share/man/html8/rc.subr.html man-rc-htmlman html
./usr/share/man/html8/rcorder.html man-sysutil-htmlman html
./usr/share/man/html8/rdate.html man-netutil-htmlman html
Index: src/etc/rc.shutdown
diff -u src/etc/rc.shutdown:1.9 src/etc/rc.shutdown:1.10
--- src/etc/rc.shutdown:1.9 Mon Jun 25 07:22:45 2012
+++ src/etc/rc.shutdown Sat Dec 7 18:45:20 2024
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# $NetBSD: rc.shutdown,v 1.9 2012/06/25 07:22:45 jnemeth Exp $
+# $NetBSD: rc.shutdown,v 1.10 2024/12/07 18:45:20 martin Exp $
#
# rc.shutdown --
# Run the scripts in /etc/rc.d with reverse rcorder.
@@ -19,6 +19,9 @@ if ! checkyesno do_rcshutdown; then
exit 0
fi
+_rcshutdown_action="$1"
+set --
+
stty status '^T'
# Set shell to ignore SIGINT, but not children;
@@ -55,6 +58,14 @@ for _rc_elem in $(reverse_list $files);
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)
#
Index: src/share/man/man8/Makefile
diff -u src/share/man/man8/Makefile:1.111 src/share/man/man8/Makefile:1.112
--- src/share/man/man8/Makefile:1.111 Fri Aug 28 12:13:09 2020
+++ src/share/man/man8/Makefile Sat Dec 7 18:45:20 2024
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.111 2020/08/28 12:13:09 christos Exp $
+# $NetBSD: Makefile,v 1.112 2024/12/07 18:45:20 martin Exp $
# from: @(#)Makefile 8.1 (Berkeley) 6/5/93
MAN= MAKEDEV.8 MAKEDEV.local.8 afterboot.8 boot.8 compat_30.8 \
@@ -17,6 +17,7 @@ MLINKS+=nis.8 yp.8
MLINKS+=rc.8 rc.d.8
MLINKS+=rc.8 rc.local.8
MLINKS+=rc.8 rc.shutdown.8
+MLINKS+=rc.8 rc.shutdown.final.8
SUBDIR= man8.acorn32 man8.alpha man8.amiga man8.atari \
man8.cobalt man8.dreamcast man8.emips man8.evbarm \
Index: src/share/man/man8/rc.8
diff -u src/share/man/man8/rc.8:1.39 src/share/man/man8/rc.8:1.40
--- src/share/man/man8/rc.8:1.39 Sat Oct 14 21:21:51 2017
+++ src/share/man/man8/rc.8 Sat Dec 7 18:45:20 2024
@@ -1,4 +1,4 @@
-.\" $NetBSD: rc.8,v 1.39 2017/10/14 21:21:51 lukem Exp $
+.\" $NetBSD: rc.8,v 1.40 2024/12/07 18:45:20 martin Exp $
.\"
.\" Copyright (c) 2000-2017 The NetBSD Foundation, Inc.
.\" All rights reserved.
@@ -27,13 +27,14 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd October 15, 2017
+.Dd December 7, 2024
.Dt RC 8
.Os
.Sh NAME
.Nm rc ,
.Nm rc.local ,
.Nm rc.shutdown ,
+.Nm rc.shutdown.final ,
.Nm rc.d/
.Nd startup and shutdown scripts
.Sh SYNOPSIS
@@ -179,6 +180,30 @@ and sources the script in a sub-shell.
If the script has a
.Sq .sh
suffix then it is sourced directly into the current shell.
+.It
+Runs
+.Pa /etc/rc.shutdown.final
+if it exists, passing the currently ongoing shutdown action, which
+will be one of:
+.Bl -bullet
+.It
+shutdown
+when going to single user mode.
+.It
+halt
+when halting the machine (but not powering it down).
+.It
+reboot
+when rebooting the machine.
+.It
+poweroff
+when halting the machine and powering it off.
+.El
+.Pp
+The script may be used for example to controll additional
+actions, e.g. powering off external devices, restarting
+a UPS (in case main power is restored in the interval betweeen
+the computer powering off and the UPS running out of battery).
.El
.Ss Contents of rc.d/
.Nm rc.d/