[arch-projects] [initscripts] [PATCH 10/12] Get rid of more simple if-constucts by using '&&' and '||'
Dave Reisner
d at falconindy.com
Sat Jun 25 14:34:03 EDT 2011
On Sat, Jun 25, 2011 at 12:16:02PM +0200, Kurt J. Bosch wrote:
> ---
> functions | 24 +++++++-----------------
> rc.sysinit | 22 ++++++----------------
> 2 files changed, 13 insertions(+), 33 deletions(-)
>
> diff --git a/functions b/functions
> index 1c6a780..86b9602 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
> @@ -335,13 +331,10 @@ udevd_modprobe() {
> activate_vgs() {
> [[ $USELVM = [yY][eE][sS] && -x $(type -P lvm) && -d /sys/block ]] || return 0
> stat_busy "Activating LVM2 groups"
> - # Kernel 2.6.x, LVM2 groups
> - /sbin/modprobe -q dm-mod 2>/dev/null
> - if /sbin/vgchange --sysinit -a y >/dev/null; then
> - stat_done
> - else
> - stat_fail
> - fi
> + # Kernel 2.6.x, LVM2 groups
> + /sbin/modprobe -q dm-mod 2>/dev/null
> + /sbin/vgchange --sysinit -a y >/dev/null
> + (( $? == 0 )) && stat_done || stat_fail
> }
>
> # Arch cryptsetup packages traditionally contained the binaries
> @@ -385,11 +378,8 @@ fsck_all() {
> fsck -A -T -C$FSCK_FD -a -t "$NETFS,noopts=_netdev" $FORCEFSCK >$FSCK_OUT 2>$FSCK_ERR
> local fsckret=$?
> run_hook sysinit_postfsck
> - if (( fsckret > 1 )); then
> - stat_fail
> - else
> - stat_done
> - fi
> + # Ignore condition 'FS errors corrected'
> + (( (fsckret | 1) == 1 )) && stat_done || stat_fail
> return $fsckret
> }
>
> diff --git a/rc.sysinit b/rc.sysinit
> index 9f44848..097b38a 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
Whitespace error here?
>
> # 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
>
> # Check filesystems
> @@ -202,7 +192,7 @@ if [[ ! -L /etc/mtab ]]; then
> else
> cat /proc/mounts >| /etc/mtab
> fi
> - if (( $? == 0 )); then stat_done; else stat_fail; fi
> + (( $? == 0 )) && stat_done || stat_fail
> fi
>
> # now mount all the local filesystems
> @@ -278,7 +268,7 @@ stat_busy "Saving dmesg Log"
> else
> install -Tm 0644 <( dmesg ) /var/log/dmesg.log
> fi
> -if (( $? == 0 )); then stat_done; else stat_fail; fi
> +(( $? == 0 )) && stat_done || stat_fail
>
> run_hook sysinit_end
>
> --
> 1.7.1
>
More information about the arch-projects
mailing list