diff options
author | Richard Yao <ryao@gentoo.org> | 2013-06-09 05:40:07 -0400 |
---|---|---|
committer | Richard Yao <ryao@cs.stonybrook.edu> | 2013-06-09 09:47:39 -0400 |
commit | a21728ae287e988a1848435ab27f7ab503def784 (patch) | |
tree | 7be014c0340ab956d2d5c90d045553b97274a92e | |
parent | Refactor ZFS module load hook (diff) | |
download | genkernel-a21728ae287e988a1848435ab27f7ab503def784.tar.gz genkernel-a21728ae287e988a1848435ab27f7ab503def784.tar.bz2 genkernel-a21728ae287e988a1848435ab27f7ab503def784.zip |
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>
-rw-r--r-- | defaults/initrd.scripts | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts index 9b0e8992..bfdde75a 100644 --- a/defaults/initrd.scripts +++ b/defaults/initrd.scripts @@ -2,6 +2,22 @@ . /etc/initrd.defaults +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 |