Received: from eggs.gnu.org ([2001:4830:134:3::10]:55002) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WFgc9-0005UQ-HO for qemu-devel@nongnu.org; Tue, 18 Feb 2014 04:05:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WFgc1-00061J-3w for qemu-devel@nongnu.org; Tue, 18 Feb 2014 04:05:17 -0500 Received: from mail-we0-x235.google.com ([2a00:1450:400c:c03::235]:45103) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WFgc0-00061F-Ty for qemu-devel@nongnu.org; Tue, 18 Feb 2014 04:05:09 -0500 Received: by mail-we0-f181.google.com with SMTP id w61so11542134wes.12 for ; Tue, 18 Feb 2014 01:05:08 -0800 (PST) Date: Tue, 18 Feb 2014 10:05:04 +0100 From: Stefan Hajnoczi Message-ID: <20140218090504.GB32585@stefanha-thinkpad.redhat.com> References: <1392651898-16749-1-git-send-email-stefanha@redhat.com> <1392651898-16749-4-git-send-email-stefanha@redhat.com> <530235F0.2040406@redhat.com> <87a9dpsmi4.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87a9dpsmi4.fsf@blackfin.pond.sub.org> Subject: Re: [Qemu-devel] [PATCH 3/3] qtest: kill QEMU process on g_assert() failure List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: Peter Maydell , Anthony Liguori , qemu-devel@nongnu.org, Stefan Hajnoczi , Paolo Bonzini , Andreas Faerber On Mon, Feb 17, 2014 at 06:00:03PM +0100, Markus Armbruster wrote: > Paolo Bonzini writes: > > > Il 17/02/2014 16:44, Stefan Hajnoczi ha scritto: > >> } > >> > >> +static void sigabrt_handler(int signo) > >> +{ > >> + qtest_end(); > >> +} > >> + > > > > void qtest_quit(QTestState *s) > > { > > int status; > > > > if (s->qemu_pid != -1) { > > kill(s->qemu_pid, SIGTERM); > > waitpid(s->qemu_pid, &status, 0); > > } > > > > close(s->fd); > > close(s->qmp_fd); > > g_string_free(s->rx, true); > > g_free(s); > > } > > > > Not async-signal safe. You need to ignore the g_string_free and > > g_free (perhaps even the closes) if calling from the sigabrt_handler. > > kill(), waitpid() and close() are all async-signal-safe. > > SIGABRT is normally synchronous enough: it's sent by abort(). But of > course, nothing stops the user from kill -ABRT. Or GLib from calling > abort() in some place where an attempt to reenter it crashes & burns. > Not sure I'd care, but I'm pretty sure I don't care for freeing stuff on > exit :) Yes, SIGABRT is synchronous for all purposes. So the only danger is that g_string_free() or g_free() could fail while we're in g_assert(false). But they don't, which makes sense because they are totally unrelated to g_assert() and therefore can handle re-entrancy. In practice there is no issue and I've tested assertion failure with glib 1.2.10. Stefan