From 39c1bf5ea0a3bce6ffcd8af79f0b924732a5b509 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20B=C3=A4chler?= Date: Thu, 27 Jan 2011 11:19:01 +0100 Subject: Fix run_hook and add_hook definitions. This patch does 3 things: 1) Use declare -fr instead of -r, as -r does not affect functions. 2) Make sure everything is only defined once, as you cannot redefine a read-only function. 3) Fix indentation. --- functions | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/functions b/functions index 718d8c4..7700709 100644 --- a/functions +++ b/functions @@ -312,22 +312,25 @@ read_crypttab() { # Declare add_hook and run_hook as read-only to prevent overwriting them. # Too bad we cannot do the same thing with hook_funcs -declare -A hook_funcs - -add_hook() { - [[ $1 && $2 ]] || return 1 - hook_funcs["$1"]+=" $2" -} - -run_hook() { - [[ $1 ]] || return 1 - local func - for func in ${hook_funcs["$1"]}; do - "${func}" - done -} - -declare -r add_hook run_hook +if [[ $RC_FUNCTIONS_HOOK_FUNCS_DEFINED -ne 1 ]]; then + declare -A hook_funcs + + add_hook() { + [[ $1 && $2 ]] || return 1 + hook_funcs["$1"]+=" $2" + } + + run_hook() { + [[ $1 ]] || return 1 + local func + for func in ${hook_funcs["$1"]}; do + "${func}" + done + } + + declare -fr add_hook run_hook + declare -r RC_FUNCTIONS_HOOK_FUNCS_DEFINED=1 +fi # Function for setting console font if required set_consolefont() { -- cgit v1.2.3