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 4B79D138200 for ; Sun, 9 Jun 2013 09:58:23 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 9000CE0802; Sun, 9 Jun 2013 09:58:22 +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 1ABD3E07FA for ; Sun, 9 Jun 2013 09:58:22 +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 32B4633E292 for ; Sun, 9 Jun 2013 09:58:21 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id D4AC3E530A for ; Sun, 9 Jun 2013 09:58:19 +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: <1370771844.171324ea0c713f4c6c7f60587e01fe6718d11874.ryao@gentoo> Subject: [gentoo-commits] proj/genkernel:ryao 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: 171324ea0c713f4c6c7f60587e01fe6718d11874 X-VCS-Branch: ryao Date: Sun, 9 Jun 2013 09:58:19 +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: 9b6e5f62-ad92-49b9-80ee-acddd745d3de X-Archives-Hash: cf1cb9a8faa2a9b8f7a4e1603eee9778 commit: 171324ea0c713f4c6c7f60587e01fe6718d11874 Author: Richard Yao gentoo org> AuthorDate: Sun Jun 9 09:40:07 2013 +0000 Commit: Richard Yao gentoo org> CommitDate: Sun Jun 9 09:57:24 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/genkernel.git;a=commit;h=171324ea 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..c8e7abb 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 + return 1 + fi + + return 0 +} + modules_load() { for module in $* do