[arch-projects] [mkinitcpio][PATCH 13/19] init_functions: move running hooks to separate func

Dave Reisner dreisner at archlinux.org
Sun May 13 13:57:16 EDT 2012


Abstract this out to the init_functions file, and allow this function
take 2+ parameters -- the hook name to be run, a user friendly short
description, and then the list of hook files to source from. While we're
at it, take advantage of the fact that hooks are now installed with
executable perms. If a hook isn't marked excutable, we skip it, thereby
removing our eval hack.

Signed-off-by: Dave Reisner <dreisner at archlinux.org>
---
 init           |   17 ++---------------
 init_functions |   16 ++++++++++++++++
 2 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/init b/init
index 7cd812f..a8915fb 100644
--- a/init
+++ b/init
@@ -23,7 +23,7 @@ else
 fi
 
 for d in ${disablehooks//,/ }; do
-    eval "hook_${d}=disabled"
+    [ -e "/hooks/$d" ] && chmod 644 "/hooks/$d"
 done
 
 [ -n "${earlymodules//[[:space:]]}" ] && modprobe -qab ${earlymodules//,/ }
@@ -37,20 +37,7 @@ if [ -z "${rootdelay}" ] || ! [ "${rootdelay}" -ge 0 ]; then
     rootdelay=10
 fi
 
-if [ -e "/hooks" ]; then
-    for h in ${HOOKS}; do
-        TST=""
-        eval "TST=\$hook_${h}"
-        if [ "${TST}" != "disabled" ]; then
-            run_hook () { msg "${h}: no run function defined"; }
-            if [ -e "/hooks/${h}" ]; then
-               . /hooks/${h}
-               msg ":: Running Hook [${h}]"
-               run_hook
-            fi
-        fi
-    done
-fi
+run_hookfunctions 'run_hook' "early hook" $HOOKS
 
 # honor the old behavior of break=y as a synonym for break=premount
 if [ "${break}" = "y" ] || [ "${break}" = "premount" ]; then
diff --git a/init_functions b/init_functions
index 60532d2..1bebf45 100644
--- a/init_functions
+++ b/init_functions
@@ -44,6 +44,22 @@ major_minor_to_device() {
     return 1
 }
 
+run_hookfunctions() {
+    local hook fn=$1 desc=$2
+
+    shift 2
+    for hook in "$@"; do
+        [ -x "/hooks/$hook" ] || continue
+
+        unset "$fn"
+        . "/hooks/$hook"
+        type "$fn" >/dev/null || continue
+
+        msg ":: running $desc [$hook]"
+        "$fn"
+    done
+}
+
 parse_cmdline() {
     local w in_quotes lhs rhs
     in_quotes=0
-- 
1.7.10.2



More information about the arch-projects mailing list