From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id D4C52138200 for ; Sun, 9 Jun 2013 13:48:31 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id CD9FAE084C; Sun, 9 Jun 2013 13:48:30 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id E3A2BE0822 for ; Sun, 9 Jun 2013 13:48:29 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 016DF33E23C for ; Sun, 9 Jun 2013 13:48:29 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id A3F22E545F for ; Sun, 9 Jun 2013 13:48:27 +0000 (UTC) From: "Richard Yao" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Richard Yao" Message-ID: <1370785659.a21728ae287e988a1848435ab27f7ab503def784.ryao@gentoo> Subject: [gentoo-commits] proj/genkernel:master commit in: defaults/ X-VCS-Repository: proj/genkernel X-VCS-Files: defaults/initrd.scripts X-VCS-Directories: defaults/ X-VCS-Committer: ryao X-VCS-Committer-Name: Richard Yao X-VCS-Revision: a21728ae287e988a1848435ab27f7ab503def784 X-VCS-Branch: master Date: Sun, 9 Jun 2013 13:48:27 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 8c88dcd9-66d8-4471-9939-0ce9b1cdbf3d X-Archives-Hash: c2b7ffafe35f3b6fb74ee167cf942fd8 Message-ID: <20130609134827.JDDGQY-8SpKlBJ174x78JtUMdZd8sM6JjVM9MRJ_KOY@z> commit: a21728ae287e988a1848435ab27f7ab503def784 Author: Richard Yao gentoo org> AuthorDate: Sun Jun 9 09:40:07 2013 +0000 Commit: Richard Yao gentoo org> CommitDate: Sun Jun 9 13:47:39 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/genkernel.git;a=commit;h=a21728ae 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 gentoo.org> --- defaults/initrd.scripts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts index 9b0e899..bfdde75 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