From c188fcedff735a6e31be7882a7b38dc3483802d9 Mon Sep 17 00:00:00 2001 From: Richard Yao Date: Sun, 9 Jun 2013 05:40:07 -0400 Subject: [PATCH] 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 Conflicts: defaults/initrd.scripts --- defaults/initrd.scripts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts index 8181681..b353817 100644 --- a/defaults/initrd.scripts +++ b/defaults/initrd.scripts @@ -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