[arch-projects] [initscripts] [PATCH 11/21] Refactor to get rid of simple if-constucts

Kurt J. Bosch kjb-temp-2009 at alpenjodel.de
Tue Jun 28 09:27:35 EDT 2011


---
 functions  |   27 +++++++--------------------
 rc.sysinit |   18 ++++--------------
 2 files changed, 11 insertions(+), 34 deletions(-)

diff --git a/functions b/functions
index ec82c6c..4c4ca0e 100644
--- a/functions
+++ b/functions
@@ -237,11 +237,7 @@ status_stopped() {
 }
 
 ck_status() {
-	if ! ck_daemon "$1"; then
-		status_started
-	else
-		status_stopped
-	fi
+	! ck_daemon "$1" && status_started || status_stopped
 }
 
 # Return PID of $1
@@ -315,9 +311,8 @@ udevd_modprobe() {
 	stat_done
 
 	# Load modules from the MODULES array defined in rc.conf
-	if [[ -f /proc/modules ]] && (( ${#MODULES[*]} )); then
+	[[ -f /proc/modules ]] && (( ${#MODULES[*]} )) &&
 		status "Loading Modules" modprobe -ab "${MODULES[@]}"
-	fi
 
 	status "Waiting for UDev uevents to be processed" \
 		udevadm settle --timeout=${UDEV_TIMEOUT:-30}
@@ -333,11 +328,8 @@ activate_vgs() {
 	# Kernel 2.6.x, LVM2 groups
 	/sbin/modprobe -q dm-mod 2>/dev/null
 	stat_busy "Activating LVM2 groups"
-	if /sbin/vgchange --sysinit -a y >/dev/null; then
-		stat_done
-	else
-		stat_fail
-	fi
+		/sbin/vgchange --sysinit -a y >/dev/null
+	(( $? == 0 )) && stat_done || stat_fail
 }
 
 # Arch cryptsetup packages traditionally contained the binaries
@@ -379,11 +371,7 @@ fsck_all() {
 		run_hook sysinit_prefsck
 		fsck -A -T -C$FSCK_FD -a -t "$NETFS,noopts=_netdev" $FORCEFSCK >|$FSCK_OUT 2>|$FSCK_ERR
 		local -r fsckret=$?
-	if (( fsckret > 1 )); then
-		stat_fail
-	else
-		stat_done
-	fi
+	(( fsckret <= 1 )) && stat_done || stat_fail
 	run_hook sysinit_postfsck
 	return $fsckret
 }
@@ -392,9 +380,8 @@ fsck_all() {
 fsck_reboot() {
 	# $1 = exit code returned by fsck
 	# Ignore conditions 'FS errors corrected' and 'Cancelled by the user'
-	if (( ($1 | 33) == 33 )); then
-		return 0
-	elif (( $1 & 2 )); then
+	(( ($1 | 33) == 33 )) && return 0
+	if (( $1 & 2 )); then
 		echo
 		echo "********************** REBOOT REQUIRED *********************"
 		echo "*                                                          *"
diff --git a/rc.sysinit b/rc.sysinit
index 27e603b..06b287c 100755
--- a/rc.sysinit
+++ b/rc.sysinit
@@ -68,11 +68,7 @@ if [[ $HWCLOCK_PARAMS ]]; then
 		# is used. If HARDWARECLOCK is not set in rc.conf, the value in
 		# /var/lib/hwclock/adjfile is used (in this case /var can not be a separate
 		# partition).
-		if TZ=$TIMEZONE hwclock $HWCLOCK_PARAMS; then
-			stat_done
-		else
-			stat_fail
-		fi
+	TZ=$TIMEZONE hwclock $HWCLOCK_PARAMS && stat_done || stat_fail
 fi
 
 # Start/trigger UDev, load MODULES and settle UDev
@@ -175,15 +171,9 @@ if [[ -f /etc/crypttab && $CS ]] && grep -q ^[^#] /etc/crypttab; then
 			return $failed
 		}
 	crypto_unlocked=0
-	if read_crypttab do_unlock; then
-		stat_done
-	else
-		stat_fail
-	fi
-	if (( crypto_unlocked == 1 )); then
-		# Maybe someone has LVM on an encrypted block device
-		activate_vgs
-	fi
+	read_crypttab do_unlock && stat_done || stat_fail
+	# Maybe someone has LVM on an encrypted block device
+	(( crypto_unlocked == 1 )) && activate_vgs
 fi
 
 if [[ -x $(type -P fsck) ]]; then
-- 
1.7.1



More information about the arch-projects mailing list