[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 15/31] libqtest: add qtest_remove_abrt_handler()
From: |
Kevin Wolf |
Subject: |
[PULL 15/31] libqtest: add qtest_remove_abrt_handler() |
Date: |
Fri, 5 Mar 2021 17:54:38 +0100 |
From: Stefan Hajnoczi <stefanha@redhat.com>
Add a function to remove previously-added abrt handler functions.
Now that a symmetric pair of add/remove functions exists we can also
balance the SIGABRT handler installation. The signal handler was
installed each time qtest_add_abrt_handler() was called. Now it is
installed when the abrt handler list becomes non-empty and removed again
when the list becomes empty.
The qtest_remove_abrt_handler() function will be used by
vhost-user-blk-test.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
Message-Id: <20210223144653.811468-5-stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
tests/qtest/libqos/libqtest.h | 18 ++++++++++++++++++
tests/qtest/libqtest.c | 35 +++++++++++++++++++++++++++++------
2 files changed, 47 insertions(+), 6 deletions(-)
diff --git a/tests/qtest/libqos/libqtest.h b/tests/qtest/libqos/libqtest.h
index 51287b9276..a68dcd79d4 100644
--- a/tests/qtest/libqos/libqtest.h
+++ b/tests/qtest/libqos/libqtest.h
@@ -649,8 +649,26 @@ void qtest_add_data_func_full(const char *str, void *data,
g_free(path); \
} while (0)
+/**
+ * qtest_add_abrt_handler:
+ * @fn: Handler function
+ * @data: Argument that is passed to the handler
+ *
+ * Add a handler function that is invoked on SIGABRT. This can be used to
+ * terminate processes and perform other cleanup. The handler can be removed
+ * with qtest_remove_abrt_handler().
+ */
void qtest_add_abrt_handler(GHookFunc fn, const void *data);
+/**
+ * qtest_remove_abrt_handler:
+ * @data: Argument previously passed to qtest_add_abrt_handler()
+ *
+ * Remove an abrt handler that was previously added with
+ * qtest_add_abrt_handler().
+ */
+void qtest_remove_abrt_handler(void *data);
+
/**
* qtest_qmp_assert_success:
* @qts: QTestState instance to operate on
diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index 2a98de2907..71e359efcd 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -196,15 +196,30 @@ static void cleanup_sigabrt_handler(void)
sigaction(SIGABRT, &sigact_old, NULL);
}
+static bool hook_list_is_empty(GHookList *hook_list)
+{
+ GHook *hook = g_hook_first_valid(hook_list, TRUE);
+
+ if (!hook) {
+ return false;
+ }
+
+ g_hook_unref(hook_list, hook);
+ return true;
+}
+
void qtest_add_abrt_handler(GHookFunc 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();
+
+ /* Only install SIGABRT handler once */
+ if (hook_list_is_empty(&abrt_hooks)) {
+ setup_sigabrt_handler();
+ }
hook = g_hook_alloc(&abrt_hooks);
hook->func = fn;
@@ -213,6 +228,17 @@ void qtest_add_abrt_handler(GHookFunc fn, const void *data)
g_hook_prepend(&abrt_hooks, hook);
}
+void qtest_remove_abrt_handler(void *data)
+{
+ GHook *hook = g_hook_find_data(&abrt_hooks, TRUE, data);
+ g_hook_destroy_link(&abrt_hooks, hook);
+
+ /* Uninstall SIGABRT handler on last instance */
+ if (hook_list_is_empty(&abrt_hooks)) {
+ cleanup_sigabrt_handler();
+ }
+}
+
static const char *qtest_qemu_binary(void)
{
const char *qemu_bin;
@@ -369,10 +395,7 @@ QTestState *qtest_init_with_serial(const char *extra_args,
int *sock_fd)
void qtest_quit(QTestState *s)
{
- g_hook_destroy_link(&abrt_hooks, g_hook_find_data(&abrt_hooks, TRUE, s));
-
- /* Uninstall SIGABRT handler on last instance */
- cleanup_sigabrt_handler();
+ qtest_remove_abrt_handler(s);
qtest_kill_qemu(s);
close(s->fd);
--
2.29.2
- [PULL 00/31] Block layer patches, Kevin Wolf, 2021/03/05
- [PULL 06/31] blockjob: report a better error message, Kevin Wolf, 2021/03/05
- [PULL 01/31] iotests: Drop deprecated 'props' from object-add, Kevin Wolf, 2021/03/05
- [PULL 15/31] libqtest: add qtest_remove_abrt_handler(),
Kevin Wolf <=
- [PULL 13/31] libqtest: add qtest_socket_server(), Kevin Wolf, 2021/03/05
- [PULL 08/31] storage-daemon: include current command line option in the errors, Kevin Wolf, 2021/03/05
- [PULL 05/31] iotests: Fix up python style in 300, Kevin Wolf, 2021/03/05
- [PULL 09/31] qemu-storage-daemon: add --pidfile option, Kevin Wolf, 2021/03/05
- [PULL 02/31] backup: Remove nodes from job in .clean(), Kevin Wolf, 2021/03/05
- [PULL 26/31] block/parallels: BDRVParallelsState: add cluster_size field, Kevin Wolf, 2021/03/05
- [PULL 11/31] docs: replace insecure /tmp examples in qsd docs, Kevin Wolf, 2021/03/05
- [PULL 19/31] block/export: use VIRTIO_BLK_SECTOR_BITS, Kevin Wolf, 2021/03/05
- [PULL 25/31] parallels.txt: fix bitmap L1 table description, Kevin Wolf, 2021/03/05
- [PULL 10/31] docs: show how to spawn qemu-storage-daemon with fd passing, Kevin Wolf, 2021/03/05