From: Philippe Seewer Date: Tue, 16 Jun 2009 12:39:35 +0000 (+0200) Subject: Add 'die()' for easier error handling X-Git-Tag: 0.1~44 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=311a2769a03d86b0278d566d40f719f980b192ae;p=thirdparty%2Fdracut.git Add 'die()' for easier error handling Printing out an errormessage and quitting is easier if there's a function to call. If the script calling die has exit trapped, like in init, the emergency_shell is automatically called. --- diff --git a/modules.d/99base/dracut-lib b/modules.d/99base/dracut-lib index df9cb52ca..336b23501 100644 --- a/modules.d/99base/dracut-lib +++ b/modules.d/99base/dracut-lib @@ -21,6 +21,12 @@ source_all() { for f in "/$1"/*.sh; do [ -f "$f" ] && . "$f"; done } +die() { + printf "FATAL: $1\n" + printf "Refusing to continue\n" + exit 1 +} + check_occurances() { # Count the number of times the character $ch occurs in $str # Return 0 if the count matches the expected number, 1 otherwise diff --git a/modules.d/99base/init b/modules.d/99base/init index e417993d9..8a5eac08c 100755 --- a/modules.d/99base/init +++ b/modules.d/99base/init @@ -47,10 +47,9 @@ fi if [ -n "$root" -a -z "${root%%error:*}" ]; then case "${root%%:*}" in - '') echo "FATAL: no root= option specified, and no network support" ;; - error) echo "FATAL: ${root#error:}" ;; + '') die "No root= option specified, and no network support" ;; + error) die "${root#error:}" ;; esac - emergency_shell fi # Network root scripts may need updated root= options,