Am 30.06.2010 23:47, schrieb Victor Lowther:
> Go ahead and declare add_hook and run_hook as readonly functions
> to prevent hooks from overwriting them. Too bad bash does not have
> lexically scoped variables -- if it does, we could do the same with
> the hook_funcs associative array.
Lots of hunks below that have nothing to do with the actual change made
here:
Here the actual patch starts, the above doesn't belong into this patch.
You should _really_ check out git add -p/-i
> # Status functions
> @@ -234,24 +235,26 @@ ck_status() {
> # single_postkillall: after all processes have been killed in rc.single
> # shutdown_poweroff: directly before powering off in rc.shutdown
> #
> -# Make sure to never override the add_hook and run_hook functions via functions.d
> +# 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() {
> - [ -z "$1" -o -z "$2" ] && return 1
> - hook_funcs["$1"]="${hook_funcs["$1"]} $2"
> + [[ $1 && $2 ]] || return 1
> + hook_funcs["$1"]+=" $2"
> }
+= in bash? Really? Didn't know that worked.
> run_hook() {
> - local func
> -
> - [ -z "$1" ] && return 1
> - for func in ${hook_funcs["$1"]}; do
> - ${func}
> - done
> + [[ $1 ]] || return 1
> + local func
> + for func in ${hook_funcs["$1"]}; do
> + "${func}"
> + done
> }
>
> +declare -r add_hook run_hook
> +
Nice, I didn't know you could do that.
> # Function for setting console font if required
> set_consolefont() {
> if [ -n "$CONSOLEFONT" ]; then