From 6f37e8f4fe831d27172ba2edd4c2a231e05315bc Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Fri, 21 Jun 2019 23:59:37 +0800 Subject: [PATCH] rc: Move stop_boot() from rc.d/fsck to rc.subr and improve it Move the stop_boot() function from rc.d/fsck to rc.subr, since we will use it in other rc.d scripts. This follows what FreeBSD does. Improve the stop_boot() function by bringing in the FreeBSD's version. Minor cleanups. --- etc/rc.d/fsck | 16 ++-------------- etc/rc.subr | 31 ++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/etc/rc.d/fsck b/etc/rc.d/fsck index b48878bbc5..0be91c3686 100644 --- a/etc/rc.d/fsck +++ b/etc/rc.d/fsck @@ -2,7 +2,6 @@ # # $NetBSD: fsck,v 1.2 2001/06/18 06:42:35 lukem Exp $ # $FreeBSD: src/etc/rc.d/fsck,v 1.4 2002/10/12 10:31:31 schweikh Exp $ -# $DragonFly: src/etc/rc.d/fsck,v 1.4 2005/11/19 21:47:32 swildner Exp $ # # PROVIDE: fsck @@ -14,27 +13,16 @@ name="fsck" start_cmd="fsck_start" stop_cmd=":" -stop_boot() -{ - # Terminate the process (which may include the parent /etc/rc) - # if booting directly to multiuser mode. - # - if [ "$autoboot" = yes ]; then - kill -TERM $$ - fi - exit 1 -} - fsck_start() { if [ "$autoboot" = no ]; then echo "Fast boot: skipping disk checks." elif [ "$autoboot" = yes ]; then - # During fsck ignore SIGQUIT + # During fsck ignore SIGQUIT trap : 3 echo "Starting file system checks:" - fsck -p + fsck -p case $? in 0) diff --git a/etc/rc.subr b/etc/rc.subr index 0ce902dbf6..469973ff40 100644 --- a/etc/rc.subr +++ b/etc/rc.subr @@ -39,6 +39,8 @@ # functions used by various rc scripts # +: ${RC_PID:=$$}; export RC_PID + # # Operating System dependent/independent variables # @@ -56,6 +58,7 @@ _rc_subr_loaded="YES" SYSCTL="/sbin/sysctl" SYSCTL_N="${SYSCTL} -n" +SYSCTL_W="${SYSCTL}" CMD_OSTYPE="${SYSCTL_N} kern.ostype" OSTYPE=`${CMD_OSTYPE}` @@ -65,7 +68,6 @@ RC_DISABLED=2 RC_IRRELEVANT=3 RC_CONFIGURED=4 RC_STOPPED=5 -SYSCTL_W="${SYSCTL}" # # functions @@ -262,6 +264,7 @@ checkyesno() esac } +# # reverse_list list # print the list in reverse order # @@ -274,6 +277,32 @@ reverse_list() echo $_revlist } +# +# stop_boot always +# If booting directly to multiuser or $always is true, +# send SIGTERM to the parent (/etc/rc) to abort the boot. +# Otherwise just exit. +# +stop_boot() +{ + local always + + case $1 in + # "yes", "true", "on", or "1" + [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) + always=true + ;; + *) + always=false + ;; + esac + if [ "$autoboot" = yes -o "$always" = true ]; then + echo "ERROR: ABORTING BOOT (sending SIGTERM to parent)!" + kill -TERM ${RC_PID} + fi + exit 1 +} + # # mount_critical_filesystems type # Go through the list of critical filesystems as provided in -- 2.41.0