From 311a2769a03d86b0278d566d40f719f980b192ae Mon Sep 17 00:00:00 2001 From: Philippe Seewer Date: Tue, 16 Jun 2009 14:39:35 +0200 Subject: [PATCH] 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. --- modules.d/99base/dracut-lib | 6 ++++++ modules.d/99base/init | 5 ++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/modules.d/99base/dracut-lib b/modules.d/99base/dracut-lib index df9cb52..336b235 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 e417993..8a5eac0 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, -- 2.7.4