From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KQPVY-0006Jm-0B for qemu-devel@nongnu.org; Tue, 05 Aug 2008 12:35:36 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KQPVW-0006GG-2r for qemu-devel@nongnu.org; Tue, 05 Aug 2008 12:35:35 -0400 Received: from [199.232.76.173] (port=43195 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KQPVV-0006G4-T6 for qemu-devel@nongnu.org; Tue, 05 Aug 2008 12:35:33 -0400 Received: from mx1.redhat.com ([66.187.233.31]:39946) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KQPVV-0003AB-HS for qemu-devel@nongnu.org; Tue, 05 Aug 2008 12:35:33 -0400 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id m75GZQVI026512 for ; Tue, 5 Aug 2008 12:35:26 -0400 Received: from file.fab.redhat.com (file.fab.redhat.com [10.33.63.6]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id m75GZJK7024476 for ; Tue, 5 Aug 2008 12:35:19 -0400 Received: (from berrange@localhost) by file.fab.redhat.com (8.13.1/8.13.1/Submit) id m75GZJfX032203 for qemu-devel@nongnu.org; Tue, 5 Aug 2008 17:35:19 +0100 Date: Tue, 5 Aug 2008 17:35:19 +0100 From: "Daniel P. Berrange" Subject: Re: [Qemu-devel] [PATCH] catch signals Message-ID: <20080805163519.GV6570@redhat.com> References: <48987B43.4090207@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <48987B43.4090207@redhat.com> Reply-To: "Daniel P. Berrange" , qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org On Tue, Aug 05, 2008 at 06:09:39PM +0200, Gerd Hoffmann wrote: > > +#ifndef _WIN32 > +static void termsig_handler(int signal) > +{ > + switch (signal) { > + case SIGSEGV: > + case SIGBUS: > + /* returning from signal handler most likely isn't going to work */ > + fprintf(stderr, "qemu: got signal %d (%s), taking emergency exit\n", > + signal, strsignal(signal)); > + exit(1); Neither of these functions are on the POSIX async-signal-safe list, so their use from signal handlers is not a good idea. 'man 7 signal' will detail the safe functions that can be used from signal handlers. http://kerneltrap.org/man/linux/man7/signal.7 > + break; > + default: > + qemu_system_shutdown_request(); This is ok it merely sets a flag > + vm_start(); /* In case we're paused */ I've not checked all the functions this calls to see if they are safe, but I have a feeling this won't be safe in general because the vm_state_notify() will invoke a number of callbacks whose content we can't predict. I think rather than trying todo anything in the signal handler, it is safest to just set a flag and have its state checked and acted upon in the main loop. Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|