From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Andreas Faerber <afaerber@suse.de>,
Anthony Liguori <aliguori@amazon.com>
Subject: [Qemu-devel] [PATCH 3/3] libqtest: use -chardev exit-on-eof to clean up QEMU
Date: Thu, 24 Jul 2014 17:39:25 +0100 [thread overview]
Message-ID: <1406219965-13214-4-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1406219965-13214-1-git-send-email-stefanha@redhat.com>
When the test case aborts it is important to terminate the QEMU process
so it does not leak. This was implemented using a SIGABRT handler
function in libqtest that sent SIGTERM to QEMU.
The SIGABRT approach is messy because it requires a global signal
handler but libqtest should support multiple simultaneous instances.
Simplify the code using the new -chardev exit-on-eof option. QEMU will
automatically exit when our qtest socket closes.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
tests/libqtest.c | 48 +++---------------------------------------------
1 file changed, 3 insertions(+), 45 deletions(-)
diff --git a/tests/libqtest.c b/tests/libqtest.c
index 98e8f4b..6c3dd27 100644
--- a/tests/libqtest.c
+++ b/tests/libqtest.c
@@ -46,12 +46,8 @@ struct QTestState
bool irq_level[MAX_IRQ];
GString *rx;
pid_t qemu_pid; /* our child QEMU process */
- struct sigaction sigact_old; /* restored on exit */
};
-static GList *qtest_instances;
-static struct sigaction sigact_old;
-
#define g_assert_no_errno(ret) do { \
g_assert_cmpint(ret, !=, -1); \
} while (0)
@@ -110,32 +106,6 @@ 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);
- }
-}
-
-static void setup_sigabrt_handler(void)
-{
- struct sigaction sigact;
-
- /* Catch SIGABRT to clean up on g_assert() failure */
- sigact = (struct sigaction){
- .sa_handler = sigabrt_handler,
- .sa_flags = SA_RESETHAND,
- };
- sigemptyset(&sigact.sa_mask);
- sigaction(SIGABRT, &sigact, &sigact_old);
-}
-
-static void cleanup_sigabrt_handler(void)
-{
- sigaction(SIGABRT, &sigact_old, NULL);
-}
-
QTestState *qtest_init(const char *extra_args)
{
QTestState *s;
@@ -156,17 +126,12 @@ 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);
-
s->qemu_pid = fork();
if (s->qemu_pid == 0) {
command = g_strdup_printf("exec %s "
- "-qtest unix:%s,nowait "
+ "-chardev socket,id=qtestdev,path=%s,nowait,"
+ "exit-on-eof "
+ "-qtest chardev:qtestdev "
"-qtest-log /dev/null "
"-qmp unix:%s,nowait "
"-machine accel=qtest "
@@ -207,13 +172,6 @@ QTestState *qtest_init(const char *extra_args)
void qtest_quit(QTestState *s)
{
- /* Uninstall SIGABRT handler on last instance */
- if (qtest_instances && !qtest_instances->next) {
- cleanup_sigabrt_handler();
- }
-
- qtest_instances = g_list_remove(qtest_instances, s);
-
kill_qemu(s);
close(s->fd);
close(s->qmp_fd);
--
1.9.3
prev parent reply other threads:[~2014-07-24 16:39 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-24 16:39 [Qemu-devel] [PATCH 0/3] libqtest: solve QEMU process cleanup problem Stefan Hajnoczi
2014-07-24 16:39 ` [Qemu-devel] [PATCH 1/3] libqemustub: add qemu_system_shutdown_request() and no_shutdown Stefan Hajnoczi
2014-07-24 17:07 ` Peter Maydell
2014-07-25 9:42 ` Stefan Hajnoczi
2014-07-24 16:39 ` [Qemu-devel] [PATCH 2/3] qemu-char: add -chardev exit-on-eof option Stefan Hajnoczi
2014-07-25 8:12 ` Markus Armbruster
2014-07-25 9:39 ` Stefan Hajnoczi
2014-07-28 23:08 ` Eric Blake
2014-07-29 6:12 ` Markus Armbruster
2014-07-29 12:58 ` Eric Blake
2014-07-29 14:41 ` Markus Armbruster
2014-07-24 16:39 ` Stefan Hajnoczi [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1406219965-13214-4-git-send-email-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=afaerber@suse.de \
--cc=aliguori@amazon.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).