Add call_func_timeout helper function

call_func_timeout permits us to call a helper function and kill it
should it exceed some timeout. This is derived from example code posted
on Stack Overflow:

http://stackoverflow.com/a/11056286

Signed-off-by: Richard Yao <ryao@gentoo.org>

Conflicts:
	defaults/initrd.scripts
master
Richard Yao 12 years ago committed by Fabio Erculiani
parent 6c0e6f6ee6
commit c188fcedff

@ -109,6 +109,22 @@ plymouth_newroot() {
is_plymouth_started && "${PLYMOUTH_BIN}" --newroot="${1}"
}
call_func_timeout()
{
local func=$1 timeout=$2 pid watcher
[ $# -ne 2 ] && gen_die "call_func_timeout() called with $# arguments"
( ${func} ) & pid=$!
( sleep ${timeout} && kill -HUP ${pid} ) 2>/dev/null & watcher=$!
if wait ${pid} 2>/dev/null; then
kill -HUP $watcher 2> /dev/null
wait $watcher 2>/dev/null
return 1
fi
return 0
}
modules_load() {
for module in $*
do

Loading…
Cancel
Save