From: Paolo Bonzini <pbonzini@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>, qemu-devel@nongnu.org
Cc: Markus Armbruster <armbru@redhat.com>,
Anthony Liguori <aliguori@amazon.com>,
Andreas Faerber <afaerber@suse.de>
Subject: Re: [Qemu-devel] [PATCH v2 3/3] qtest: kill QEMU process on g_assert() failure
Date: Tue, 18 Feb 2014 16:38:25 +0100 [thread overview]
Message-ID: <53037E71.80203@redhat.com> (raw)
In-Reply-To: <1392735289-19484-4-git-send-email-stefanha@redhat.com>
Il 18/02/2014 15:54, Stefan Hajnoczi ha scritto:
> The QEMU process stays running if the test case fails. This patch fixes
> the leak by installing a SIGABRT signal handler which invokes
> qtest_end().
>
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
> tests/libqtest.c | 31 +++++++++++++++++++++++++------
> 1 file changed, 25 insertions(+), 6 deletions(-)
>
> diff --git a/tests/libqtest.c b/tests/libqtest.c
> index 8b2b2d7..f587d36 100644
> --- a/tests/libqtest.c
> +++ b/tests/libqtest.c
> @@ -44,6 +44,7 @@ struct QTestState
> bool irq_level[MAX_IRQ];
> GString *rx;
> pid_t qemu_pid; /* our child QEMU process */
> + struct sigaction sigact_old; /* restored on exit */
> };
>
> #define g_assert_no_errno(ret) do { \
> @@ -88,6 +89,19 @@ static int socket_accept(int sock)
> return ret;
> }
>
> +static void kill_qemu(QTestState *s)
> +{
> + if (s->qemu_pid != -1) {
> + kill(s->qemu_pid, SIGTERM);
> + waitpid(s->qemu_pid, NULL, 0);
> + }
> +}
> +
> +static void sigabrt_handler(int signo)
> +{
> + kill_qemu(global_qtest);
> +}
> +
> QTestState *qtest_init(const char *extra_args)
> {
> QTestState *s;
> @@ -96,6 +110,7 @@ QTestState *qtest_init(const char *extra_args)
> gchar *qmp_socket_path;
> gchar *command;
> const char *qemu_binary;
> + struct sigaction sigact;
>
> qemu_binary = getenv("QTEST_QEMU_BINARY");
> g_assert(qemu_binary != NULL);
> @@ -108,6 +123,14 @@ QTestState *qtest_init(const char *extra_args)
> sock = init_socket(socket_path);
> qmpsock = init_socket(qmp_socket_path);
>
> + /* 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, &s->sigact_old);
> +
> s->qemu_pid = fork();
> if (s->qemu_pid == 0) {
> command = g_strdup_printf("exec %s "
> @@ -148,13 +171,9 @@ QTestState *qtest_init(const char *extra_args)
>
> void qtest_quit(QTestState *s)
> {
> - int status;
> -
> - if (s->qemu_pid != -1) {
> - kill(s->qemu_pid, SIGTERM);
> - waitpid(s->qemu_pid, &status, 0);
> - }
> + sigaction(SIGABRT, &s->sigact_old, NULL);
>
> + kill_qemu(s);
> close(s->fd);
> close(s->qmp_fd);
> g_string_free(s->rx, true);
>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
next prev parent reply other threads:[~2014-02-18 15:38 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-18 14:54 [Qemu-devel] [PATCH v2 0/3] qtest: avoid pidfile and QEMU process leaks Stefan Hajnoczi
2014-02-18 14:54 ` [Qemu-devel] [PATCH v2 1/3] qtest: drop unused child_pid field Stefan Hajnoczi
2014-02-18 14:54 ` [Qemu-devel] [PATCH v2 2/3] qtest: make QEMU our direct child process Stefan Hajnoczi
2014-02-18 14:54 ` [Qemu-devel] [PATCH v2 3/3] qtest: kill QEMU process on g_assert() failure Stefan Hajnoczi
2014-02-18 15:38 ` Paolo Bonzini [this message]
2014-02-18 16:32 ` [Qemu-devel] [PATCH v2 0/3] qtest: avoid pidfile and QEMU process leaks Markus Armbruster
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=53037E71.80203@redhat.com \
--to=pbonzini@redhat.com \
--cc=afaerber@suse.de \
--cc=aliguori@amazon.com \
--cc=armbru@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/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).