From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53160) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YQgOV-00031U-5G for qemu-devel@nongnu.org; Wed, 25 Feb 2015 13:09:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YQgOQ-0001lY-49 for qemu-devel@nongnu.org; Wed, 25 Feb 2015 13:09:11 -0500 From: Max Reitz Date: Wed, 25 Feb 2015 13:08:35 -0500 Message-Id: <1424887718-10800-23-git-send-email-mreitz@redhat.com> In-Reply-To: <1424887718-10800-1-git-send-email-mreitz@redhat.com> References: <1424887718-10800-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH 22/25] iotests: Add _timeout function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-block@nongnu.org Cc: Kevin Wolf , Paolo Bonzini , qemu-devel@nongnu.org, Stefan Hajnoczi , Max Reitz Add a function for executing a command with a timeout. Signed-off-by: Max Reitz --- tests/qemu-iotests/common.rc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc index 22d3514..bd8453a 100644 --- a/tests/qemu-iotests/common.rc +++ b/tests/qemu-iotests/common.rc @@ -489,5 +489,21 @@ _die() exit 1 } +_timeout() +{ + local timeout=1 + local pid + + if [ "$1" = "-t" ]; then + shift + timeout=$1 + shift + fi + "$@" & + pid=$! + (sleep $timeout; kill -9 $pid &> /dev/null) & + wait -n $pid $! +} + # make sure this script returns success true -- 2.1.0