From: Jamie Lokier Subject: Re: [PATCH 01/13] Handle terminating signals. Date: Tue, 26 Aug 2008 18:55:18 +0100 Message-ID: <20080826175518.GD25893@shareable.org> References: <1219336054-15919-1-git-send-email-kraxel@redhat.com> <1219336054-15919-2-git-send-email-kraxel@redhat.com> <18611.56975.584280.471257@mariner.uk.xensource.com> <48B3F411.2020306@redhat.com> <18611.63711.631859.280983@mariner.uk.xensource.com> <48B3FDFA.2010905@redhat.com> Reply-To: qemu-devel@nongnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Content-Disposition: inline In-Reply-To: <48B3FDFA.2010905@redhat.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+gceq-qemu-devel=gmane.org@nongnu.org Errors-To: qemu-devel-bounces+gceq-qemu-devel=gmane.org@nongnu.org To: qemu-devel@nongnu.org Cc: xen-devel@lists.xensource.com, Ian Jackson List-Id: xen-devel@lists.xenproject.org Gerd Hoffmann wrote: > Ian Jackson wrote: > > Gerd Hoffmann writes ("Re: [Qemu-devel] [PATCH 01/13] Handle terminating signals."): > >> What this would be useful for? The termination signals usualy one-shot > >> anyway, so I don't see any advantage in doing the pipe-to-self trick. > > > > The point is that then they can interrupt select(). > > Sure, basically any signal can interrupt any system call. I still don't > see the point you are trying to make. Signals interrupting system calls has nothing to do with it. The point is this sequence: 1. Check for signals / flags from signals... nope. [[ 2. Signal arrives! Sets flag. ]] 3. Call select(). The signal occurs _after_ the main loop checks for wakeup conditons, but _before_ select() is called. It doesn't interrupt select() because that hasn't started yet. Result: select() blocks for a long time. In the fixed version, the signal handler writes to the self-pipe, and select() is called in the main loop, and returns immediately because the self-pipe is ready to read. (The data in it is ignored, just read to empty it.) The other way this can be done is for the signal handler to call siglongjmp(). But that's slower (every call to select() must call sigsetjmp() which is a bit slow), and crashes some OSes. The self-pipe is well known for being reliable. -- Jamie