From patchwork Tue Sep 15 16:07:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 518005 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id AF6EE1401B5 for ; Wed, 16 Sep 2015 02:29:52 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=zhVD5JSi; dkim-atps=neutral Received: from localhost ([::1]:44350 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zbt78-00069u-PL for incoming@patchwork.ozlabs.org; Tue, 15 Sep 2015 12:29:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57831) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zbsp6-0008Nr-M4 for qemu-devel@nongnu.org; Tue, 15 Sep 2015 12:11:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zbsp5-0006fN-PJ for qemu-devel@nongnu.org; Tue, 15 Sep 2015 12:11:12 -0400 Received: from mail-qg0-x22e.google.com ([2607:f8b0:400d:c04::22e]:35726) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zbsp5-0006el-K3 for qemu-devel@nongnu.org; Tue, 15 Sep 2015 12:11:11 -0400 Received: by qgt47 with SMTP id 47so146967011qgt.2 for ; Tue, 15 Sep 2015 09:11:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=imOyADRjjaOLMXf590rmCBGHVT4+BJ3jJzH3c2aPZ4Y=; b=zhVD5JSit4WP1D8RphpdMxb2vDdixTcshRD9v3Wr9Na8bSbXhxVIqPqIx0586nJ6Xp MGCcvGepAXzdttwyhiy/0y45cUplzedOfQmdBXeCDFBttVO1NpMjMa9+ZT1aoZeimkuc morHgCzSQWZmL10HMDYv/ALAZWE6ki+jHmh2DuDZ8xNy5MBpMeHRa5Aqa6Ulm6CDapq3 m6ZOk9CmZ+i6CVCmYqJJ5C+ivWa89szy7rQI0yrKoS+Haop+o+IEzDD9/Wzd66ulm7UP O4zq0asO8H31RNoQPVbJJlsWpMPN/Razfd4TVCG1fBBIsxlITbgLSxFnAUpGzFssvN4r PEmA== X-Received: by 10.140.216.202 with SMTP id m193mr35187712qhb.30.1442333471010; Tue, 15 Sep 2015 09:11:11 -0700 (PDT) Received: from localhost (bne75-h02-31-39-163-232.dsl.sta.abo.bbox.fr. [31.39.163.232]) by smtp.gmail.com with ESMTPSA id 142sm8167721qhg.13.2015.09.15.09.11.09 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 Sep 2015 09:11:10 -0700 (PDT) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Date: Tue, 15 Sep 2015 18:07:56 +0200 Message-Id: <1442333283-13119-40-git-send-email-marcandre.lureau@redhat.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1442333283-13119-1-git-send-email-marcandre.lureau@redhat.com> References: <1442333283-13119-1-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400d:c04::22e Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , drjones@redhat.com, cam@cs.ualberta.ca, stefanha@redhat.com Subject: [Qemu-devel] [PATCH v3 39/46] qtest: add qtest_add_abrt_handler() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Marc-André Lureau Allow a test to add abort handlers, use GHook for all handlers. There is currently no way to remove a handler, but it could be later added if needed. Signed-off-by: Marc-André Lureau --- tests/libqtest.c | 37 ++++++++++++++++++++++++------------- tests/libqtest.h | 2 ++ 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/tests/libqtest.c b/tests/libqtest.c index e5188e0..4a3a6ad 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -49,6 +49,7 @@ struct QTestState struct sigaction sigact_old; /* restored on exit */ }; +static GHookList abrt_hooks; static GList *qtest_instances; static struct sigaction sigact_old; @@ -112,10 +113,7 @@ static void kill_qemu(QTestState *s) static void sigabrt_handler(int signo) { - GList *elem; - for (elem = qtest_instances; elem; elem = elem->next) { - kill_qemu(elem->data); - } + g_hook_list_invoke(&abrt_hooks, FALSE); } static void setup_sigabrt_handler(void) @@ -136,6 +134,23 @@ static void cleanup_sigabrt_handler(void) sigaction(SIGABRT, &sigact_old, NULL); } +void qtest_add_abrt_handler(void (*fn), const void *data) +{ + GHook *hook; + + /* Only install SIGABRT handler once */ + if (!abrt_hooks.is_setup) { + g_hook_list_init(&abrt_hooks, sizeof(GHook)); + setup_sigabrt_handler(); + } + + hook = g_hook_alloc(&abrt_hooks); + hook->func = fn; + hook->data = (void *)data; + + g_hook_prepend(&abrt_hooks, hook); +} + QTestState *qtest_init(const char *extra_args) { QTestState *s; @@ -156,12 +171,7 @@ QTestState *qtest_init(const char *extra_args) sock = init_socket(socket_path); qmpsock = init_socket(qmp_socket_path); - /* Only install SIGABRT handler once */ - if (!qtest_instances) { - setup_sigabrt_handler(); - } - - qtest_instances = g_list_prepend(qtest_instances, s); + qtest_add_abrt_handler(kill_qemu, s); s->qemu_pid = fork(); if (s->qemu_pid == 0) { @@ -209,13 +219,14 @@ QTestState *qtest_init(const char *extra_args) void qtest_quit(QTestState *s) { + qtest_instances = g_list_remove(qtest_instances, s); + g_hook_destroy_link(&abrt_hooks, g_hook_find_data(&abrt_hooks, TRUE, s)); + /* Uninstall SIGABRT handler on last instance */ - if (qtest_instances && !qtest_instances->next) { + if (!qtest_instances) { cleanup_sigabrt_handler(); } - qtest_instances = g_list_remove(qtest_instances, s); - kill_qemu(s); close(s->fd); close(s->qmp_fd); diff --git a/tests/libqtest.h b/tests/libqtest.h index ec42031..f02c07c 100644 --- a/tests/libqtest.h +++ b/tests/libqtest.h @@ -427,6 +427,8 @@ void qtest_add_data_func(const char *str, const void *data, void (*fn)); g_free(path); \ } while (0) +void qtest_add_abrt_handler(void (*fn), const void *data); + /** * qtest_start: * @args: other arguments to pass to QEMU