[arch-projects] any interest?: initcpio cleanup_hook function
Dave Reisner
d at falconindy.com
Fri Mar 16 00:12:16 EDT 2012
On Thu, Mar 15, 2012 at 07:12:22PM -0600, Matthew Monaco wrote:
> This has *not* been tested. I just wanted to see if there'd be any interest.
>
> "cleanup_hook" is run in the reverse order of run_hooks, if available.
>
> This would be useful to the dropbear hook in AUR. I know systemd is killing off
> processes automatically, but even if initcpio/initscripts started doing this,
> dropbear still sets up a network interface. Unlike the net hook, dropbear's
> setup is meant to be undone.
>
> diff --git i/init w/init
> index 1f5f865..e9a6924 100644
> --- i/init
> +++ w/init
> @@ -43,33 +43,48 @@ 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
> +
> + for h in $(echo -n "${HOOKS} " | tac -s' '); do
> + TST=""
> + eval "TST=\$hook_${h}"
> + if [ "${TST}" != "disabled" ]; then
> + unset cleanup_hook
> + if [ -e "/hooks/${h}" ]; then
> + . /hooks/${h}
> + if [ "$(type -t foo 2>/dev/null)" == function ]; then
> + msg ":: Running Hook Cleanup [${h}]"
> + cleanup_hook
> + fi
> + fi
> + fi
> + done
I might be convinced that this is a decent idea if there was more than
one use case for it (in particular, one that existed in the repos).
Riffing on the theme, I'd rather see cleanup hook collection done when
hooks are run, and not make a full second pass over the hooks... might
look something like:
for h in $HOOKS; do
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
if type run_cleanup >/dev/null; then
CLEANUP_HOOKS="$hook $CLEANUP_HOOKS"
fi
fi
fi
done
for h in $CLEANUP_HOOKS; do
msg ":: Running Cleanup [$h]"
. /hooks/$h
run_cleanup
done
> fi
>
> # honor the old behavior of break=y as a synonym for break=premount
More information about the arch-projects
mailing list