From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KQRS0-0002tu-OJ for qemu-devel@nongnu.org; Tue, 05 Aug 2008 14:40:04 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KQRRw-0002oM-EB for qemu-devel@nongnu.org; Tue, 05 Aug 2008 14:40:03 -0400 Received: from [199.232.76.173] (port=45329 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KQRRw-0002o2-4n for qemu-devel@nongnu.org; Tue, 05 Aug 2008 14:40:00 -0400 Received: from mail2.shareable.org ([80.68.89.115]:38120) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KQRRu-0006gd-H1 for qemu-devel@nongnu.org; Tue, 05 Aug 2008 14:39:59 -0400 Date: Tue, 5 Aug 2008 19:39:51 +0100 From: Jamie Lokier Subject: Re: [Qemu-devel] [PATCH] catch signals Message-ID: <20080805183951.GC28513@shareable.org> References: <48987B43.4090207@redhat.com> <20080805163519.GV6570@redhat.com> <20080805165321.GZ4478@implementation.uk.xensource.com> <20080805170048.GY6570@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20080805170048.GY6570@redhat.com> Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Daniel P. Berrange" , qemu-devel@nongnu.org Cc: Samuel Thibault Daniel P. Berrange wrote: > On Tue, Aug 05, 2008 at 05:53:21PM +0100, Samuel Thibault wrote: > > Daniel P. Berrange, le Tue 05 Aug 2008 17:35:19 +0100, a écrit : > > > 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. > > > > We can not do that for SIGSEGV/SIGBUS, however. > > We shouldn't be trying todo anything for SEGV/BUS. It is basically game > over at that point - you've no chance of orderly shutdown. Only QUIT, INT, > TERM, HUP should be trying todo graceful shutdown, because those don't > imply your process is corrupting its memory/ doing bad stuff. If you can detect _where_ is triggering SIGSEGV/SIGBUS, and it's in generated code, then you've got a good chance of treating it as a special kind of trap and aborting cleanly. Also, while orderly shutdown is not possible, some subsystems could register an "emergency shutdown" hook which is async-signal-safe. Logging would have to be disabled during them, and they'd just do things to tidy up, e.g. unlinking temporary files, writing memory/disk state to an emergency snapshot if that's possible, complete pending writes to disk image formats if that makes them safer. I do something like that in a program of mine: register cleanup handlers, and some of them say "can be called from an emergency signal". Finally, another reason to have emergency cleanups is when you send SIGTERM but it's wedged, and the main loop isn't responding. After a while, you want to kill the thing, and a bit of signal-safe cleanup then is good. -- Jamie