From patchwork Fri Oct 2 19:09:42 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: 525763 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 8CE34140D6D for ; Sat, 3 Oct 2015 05:40:09 +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=EFBK0joh; dkim-atps=neutral Received: from localhost ([::1]:34745 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zi6Bb-0001fM-4r for incoming@patchwork.ozlabs.org; Fri, 02 Oct 2015 15:40:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34407) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zi5jW-0007h2-6O for qemu-devel@nongnu.org; Fri, 02 Oct 2015 15:11:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zi5jU-00082r-8O for qemu-devel@nongnu.org; Fri, 02 Oct 2015 15:11:06 -0400 Received: from mail-wi0-x235.google.com ([2a00:1450:400c:c05::235]:36333) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zi5jU-00082d-2C for qemu-devel@nongnu.org; Fri, 02 Oct 2015 15:11:04 -0400 Received: by wicgb1 with SMTP id gb1so45875235wic.1 for ; Fri, 02 Oct 2015 12:11:03 -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=EFBK0johNcH5845PYCfd/HXpCQP7H4lKduSwLoGN+P5OgMnGcXolOQC35S6ilA69Rq ULDb2K5fewGnzdIAqwIPttbFtQUD1A7j77xS7t7tTIUoujnAHhV5QgMPF1tI0I8cBOMg n7RCSEcZiC+2G4p+fos9iElWK/z2gvVO4kmu8/JQnNBcQwJVwMV7RkBvRH+5k27W0Q44 X0jrVGCtYkfhC6Y3qTjM1RwBeHcsKoZfeE7BPH/z+pWjmdk3wL3j5vwdGk2FKDlpDnit aA3DVrzy3bCuCmhii1QJrrQxcdqwYO7tBgCX9nDP8od5gJIwp8D/aGM0+I24MU++J05j L6eQ== X-Received: by 10.194.175.232 with SMTP id cd8mr19668939wjc.45.1443813063537; Fri, 02 Oct 2015 12:11:03 -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 ew2sm398800wic.20.2015.10.02.12.11.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Oct 2015 12:11:02 -0700 (PDT) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Date: Fri, 2 Oct 2015 21:09:42 +0200 Message-Id: <1443812991-17356-40-git-send-email-marcandre.lureau@redhat.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1443812991-17356-1-git-send-email-marcandre.lureau@redhat.com> References: <1443812991-17356-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: 2a00:1450:400c:c05::235 Cc: drjones@redhat.com, claudio.fontana@huawei.com, stefanha@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , pbonzini@redhat.com, cam@cs.ualberta.ca Subject: [Qemu-devel] [PATCH v5 39/48] 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 Reviewed-by: Claudio Fontana --- 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