Return-Path: X-Original-To: apmail-httpd-modules-dev-archive@minotaur.apache.org Delivered-To: apmail-httpd-modules-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7E89B10AEA for ; Fri, 1 May 2015 14:24:13 +0000 (UTC) Received: (qmail 32733 invoked by uid 500); 1 May 2015 14:24:13 -0000 Delivered-To: apmail-httpd-modules-dev-archive@httpd.apache.org Received: (qmail 32687 invoked by uid 500); 1 May 2015 14:24:13 -0000 Mailing-List: contact modules-dev-help@httpd.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: modules-dev@httpd.apache.org Delivered-To: mailing list modules-dev@httpd.apache.org Received: (qmail 32675 invoked by uid 99); 1 May 2015 14:24:12 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 May 2015 14:24:12 +0000 X-ASF-Spam-Status: No, hits=3.8 required=5.0 tests=HK_RANDOM_ENVFROM,HK_RANDOM_FROM,HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: message received from 54.76.25.247 which is an MX secondary for modules-dev@httpd.apache.org) Received: from [54.76.25.247] (HELO mx1-eu-west.apache.org) (54.76.25.247) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 May 2015 14:23:47 +0000 Received: from mail-ie0-f178.google.com (mail-ie0-f178.google.com [209.85.223.178]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with ESMTPS id 2A5D325FC3 for ; Fri, 1 May 2015 14:23:46 +0000 (UTC) Received: by iedfl3 with SMTP id fl3so101227317ied.1 for ; Fri, 01 May 2015 07:23:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=JP2AJbS/d7VRyX1M4KgmvZgvyun6fpKX5vUTtJamnIk=; b=y72pJ14hVAT+EGhfy3M9EkA6mMT4lRDnjTjhH2AEge0KMICc//1Joxr/X4M1Xck84o lLVzag3PpjzrTbSlJSLR7EMeHIc8SDrLu8acNTCpEp1duFjGC64QwOWSXbnZ+vCXRlHw /QbjR3ij4honk7Y2SmegJhyyUKgiGZan5FM7/obc5qTeGPiS6qwnomZuKCVPGAtG4kaq ZLY0l699z11HNqyRL1bfxZbiVcGz3Ws1Hy5aQfT4/UJE764UEVyVT/ufuJzzl/4UeH0Z 1EQHSnGv1bz1tA74m4sI0v1TONaS2hXcmEROkx0zIHPq/vv3vqNSGdnZU0ajRnzYwgMk 4WMQ== MIME-Version: 1.0 X-Received: by 10.50.142.2 with SMTP id rs2mr10480001igb.1.1430490190186; Fri, 01 May 2015 07:23:10 -0700 (PDT) Received: by 10.50.70.74 with HTTP; Fri, 1 May 2015 07:23:10 -0700 (PDT) In-Reply-To: <5535887B.1040708@gmail.com> References: <5535887B.1040708@gmail.com> Date: Fri, 1 May 2015 09:23:10 -0500 Message-ID: Subject: Re: Best practice for handling synchronous signals SIGFPE etc From: Mark Taylor To: modules-dev@httpd.apache.org Content-Type: multipart/alternative; boundary=001a1133d3d2a43343051505f35c X-Virus-Checked: Checked by ClamAV on apache.org --001a1133d3d2a43343051505f35c Content-Type: text/plain; charset=UTF-8 Great information, thanks all! -Mark On Mon, Apr 20, 2015 at 6:15 PM, Sorin Manolache wrote: > On 2015-04-20 21:50, Mark Taylor wrote: > >> I found that ./server/mpm_unix.c is registering a handler (sig_coredump) >> for SIGFPE, SIGSEGV, and other synchronous signals. I'd like to handle at >> least these two in my module, using my own handler. But then how do I >> determine if the the handler is called on a request thread or a server >> thread? And I'd like to default to still run the sig_coredump() function >> if >> it's signal is not in my module. >> >> > Have a look at the man-page of sigaction and getcontext. When you set a > signal handler you get the old signal handler (3rd argument of sigaction). > So you can store it in a variable. In your own signal handler you do want > you intend to do and at the end you call the old signal handler. In this > way you can call sig_coredump. However you have to make sure that you set > your signal handler _after_ apache has set his. Otherwise apache will > replace yours. > > Have a look at the siginfo_t structure that is passed by the OS to your > handler. You can get the program ID and the user ID from that structure. > But not the thread apparently. Anyway, at least you can determine if the > signal was raised in the parent or one of the worker children. > > Look also at the ucontext structure (man getcontext) that is passed to > your signal handler. Maybe you can determine the source of the signal from > that structure, though I think it's too close to machine code and registers > to be useful. > > Alternately, you could use a thread-local variable ( > https://gcc.gnu.org/onlinedocs/gcc-3.3/gcc/Thread-Local.html). The first > thing you do when you enter each function of your module is to set the > variable. Whenever you exit a function you reset it. Thus, you may > determine in your signal handler by inspection of the variable if the > signal was raised by your module. (This works only if the signal handler is > executed in the thread where the signal was raised which is not always the > case. Otherwise you'll set some variable in your thread and read another > one in the handler. Here's some information: > http://stackoverflow.com/questions/11679568/signal-handling-with-multiple-threads-in-linux. > Apparently the handlers for SIGSEGV and SIGFPE are called in the thread > that raised them but it's not clear.) > > Sorin > > > --001a1133d3d2a43343051505f35c--