diff options
author | Thomas Bächler <thomas@archlinux.org> | 2009-08-25 12:57:02 +0200 |
---|---|---|
committer | Thomas Bächler <thomas@archlinux.org> | 2009-08-25 12:57:02 +0200 |
commit | cfabb85924f35c636550609b332d088aaae9941f (patch) | |
tree | db508828fde2166a8accfd3251da461642812057 /functions | |
parent | 76bb11cb8b5374ff2bba79afc80c408f61779f0c (diff) |
Implement a hook-system that allows to add custom code to the initscripts at certain places
A function add_hook can be called from functions.d to register a hook function. The existing hooks
are based on suggestions from Michael Towers (larch) and on the implementation of initscripts-extras-fbsplash
which currently uses the strings passed to stat_busy and stat_done for this. More hooks can
be added if requested.
The implementation uses associative arrays and will thus only work with bash 4 or later
Diffstat (limited to 'functions')
-rw-r--r-- | functions | 46 |
1 files changed, 45 insertions, 1 deletions
@@ -229,8 +229,52 @@ ck_status() { fi } +############################### +# Custom hooks in initscripts # +############################### +# Hooks can be used to include custom code in various places in the rc.* scripts +# +# Define a hook function in a functions.d file using: +# function_name() { +# ... +# } +# add_hook hook_name function_name +# It's allowed to register several hook functions for the same hook +# +# The function takes the filename of the script that launched it as an argument +# +# Currently, the following hooks exist: +# start: at the beginning of rc.{multi,shutdown,single,sysinit} +# end: at the end of rc.{multi,single,sysinit} +# udevlaunched: after udev has been launched in rc.sysinit and rc.single +# udevsettled: after uevents have settled in rc.sysinit and rc.single +# premount: before local filesystems are mounted, but after root is mounted read-write in rc.sysinit +# prekillall: before all processes are being killed in rc.shutdown and rc.single +# postkillall: after all processes have been killed in rc.shutdown and rc.single +# poweroff: directly before powering off in rc.shutdown +# +# Make sure to never override the add_hook and run_hook functions via functions.d + +declare -A hook_funcs +for hook in start end udevlaunched udevsettled premount prekillall postkillall poweroff; do + hook_funcs["${hook}"]="" +done + +add_hook() { + [ -z "$1" -o -z "$2" ] && return 1 + hook_funcs["$1"]="${hook_funcs["$1"]} $2" +} + +run_hook() { + local func + + [ -z "$1" ] && return 1 + for func in ${hook_funcs["$1"]}; do + ${func} "$2" + done +} -#Source additional functions at the end to allow overrides +# Source additional functions at the end to allow overrides for f in /etc/rc.d/functions.d/*; do if [ -e $f ]; then . $f |