[arch-projects] [initscripts] [PATCH 06/13] rc.sysinit/functions: Refactor kill_everything/fsck_all/mount_all
Kurt J. Bosch
kjb-temp-2009 at alpenjodel.de
Sun Jul 3 16:31:08 EDT 2011
Genaral scheme is:
run_hook pre_foo
if [[$WE_WANT_TO_DO_FOO]]]; then
stat_busy "Doing foo"
if [[$PRECONDITIONS_FOR_FOO_NOT_SATISFIED]]; then
stat_fail
else
...
stat_done
fi
fi
run hook post_foo
rc.sysinit
-----------
run_hook pre_foo
[[$WE_WANT_TO_DO_FOO]] && status "Doing foo" foo
run hook post_foo
functions
------------
foo() {
[[$PRECONDITIONS_FOR_FOO_NOT_SATISFIED]] && return 1
...
}
Suggested-by: Tom Gundersen <teg at jklm.no>
---
functions | 26 +++++++-------------------
rc.sysinit | 24 +++++++++++++++++++++---
2 files changed, 28 insertions(+), 22 deletions(-)
diff --git a/functions b/functions
index 7acb855..c68a4a6 100644
--- a/functions
+++ b/functions
@@ -284,9 +284,10 @@ kill_everything() {
ck_daemon ${DAEMONS[i]#@} || stop_daemon ${DAEMONS[i]#@}
done
+ run_hook "$1_prekillall"
+
# Terminate all processes
stat_busy "Sending SIGTERM To Processes"
- run_hook "$1_prekillall"
killall5 -15 ${omit_pids[@]/#/-o } &>/dev/null
sleep 5
stat_done
@@ -360,23 +361,14 @@ read_crypttab() {
return $failed
}
+# Filesystem functions
+# These can be overridden for customizations like shutdown/loop-fsck.
NETFS="nonfs,nonfs4,nosmbfs,nocifs,nocodafs,noncpfs,nosysfs,noshfs,nofuse,nofuseblk,noglusterfs,nodavfs"
# Check local filesystems
fsck_all() {
- [[ -x $(type -P fsck) ]] || return 0
- stat_busy "Checking Filesystems"
- FSCK_OUT=/dev/stdout
- FSCK_ERR=/dev/stdout
- FSCK_FD=
- FORCEFSCK=
- [[ -f /forcefsck ]] || in_array forcefsck $(< /proc/cmdline) && FORCEFSCK="-- -f"
- run_hook sysinit_prefsck
- fsck -A -T -C$FSCK_FD -a -t "$NETFS,noopts=_netdev" $FORCEFSCK >|$FSCK_OUT 2>|$FSCK_ERR
- local -r fsckret=$?
- (( fsckret <= 1 )) && stat_done || stat_fail
- run_hook sysinit_postfsck
- return $fsckret
+ fsck -A -T -C$FSCK_FD -a -t "$NETFS,noopts=_netdev" $FORCEFSCK >|$FSCK_OUT 2>|$FSCK_ERR
+ return $?
}
# Single-user login and/or automatic reboot after fsck (if needed)
@@ -415,11 +407,7 @@ fsck_reboot() {
}
mount_all() {
- stat_busy "Mounting Local Filesystems"
- run_hook sysinit_premount
- mount -a -t "$NETFS" -O no_netdev
- run_hook sysinit_postmount
- stat_done
+ mount -a -t "$NETFS" -O no_netdev
}
bootlogd_stop() {
diff --git a/rc.sysinit b/rc.sysinit
index cb0144c..c3610dc 100755
--- a/rc.sysinit
+++ b/rc.sysinit
@@ -174,9 +174,24 @@ if [[ -f /etc/crypttab && $CS ]] && grep -q ^[^#] /etc/crypttab; then
fi
# Check filesystems
-fsck_all
+FSCK_OUT=/dev/stdout
+FSCK_ERR=/dev/stdout
+FSCK_FD=
+FORCEFSCK=
+[[ -f /forcefsck ]] || is_in_array forcefsck $(< /proc/cmdline) && FORCEFSCK="-- -f"
+run_hook sysinit_prefsck
+if [[ -x $(type -P fsck) ]]; then
+ stat_busy "Checking Filesystems"
+ fsck_all
+ declare -r fsckret=$?
+ (( fsckret <= 1 )) && stat_done || stat_fail
+else
+ declare -r fsckret=0
+fi
+run_hook sysinit_postfsck
+
# Single-user login and/or automatic reboot if needed
-fsck_reboot $?
+fsck_reboot $fsckret
status "Remounting Root Read/Write" \
mount -n -o remount,rw /
@@ -193,7 +208,10 @@ if [[ ! -L /etc/mtab ]]; then
fi
# now mount all the local filesystems
-mount_all
+run_hook sysinit_premount
+status "Mounting Local Filesystems" \
+ mount_all
+run_hook sysinit_postmount
# enable monitoring of lvm2 groups, now that the filesystems are mounted rw
[[ $USELVM = [Yy][Ee][Ss] && -x $(type -P lvm) && -d /sys/block ]] &&
--
1.7.1
More information about the arch-projects
mailing list