From owner-freebsd-hackers@FreeBSD.ORG Wed May 22 23:09:47 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 2925F84C for ; Wed, 22 May 2013 23:09:47 +0000 (UTC) (envelope-from mjguzik@gmail.com) Received: from mail-we0-x22f.google.com (mail-we0-x22f.google.com [IPv6:2a00:1450:400c:c03::22f]) by mx1.freebsd.org (Postfix) with ESMTP id B669EE60 for ; Wed, 22 May 2013 23:09:46 +0000 (UTC) Received: by mail-we0-f175.google.com with SMTP id p60so1763407wes.34 for ; Wed, 22 May 2013 16:09:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; bh=pe2xjxp1FDyE9ZupIxApqc4AH6EpgQWgslBrj8OvYGM=; b=yiSMQWXwU9fkC3LlCtSfV1ImJZ08eyg/49s1XX4rceIlxxaKYhc/UQY/jIowQKcQSX pUdAe4ych/Z39/X+/0gcL68qo7WSMJhWAtnNGjovc1tPrz22/tMswJAJHRgGMl43fPkr 11ah1Cj/Aj1x2byigqqcvwN2F5PqCVoR4wew5cXFvUdLAIuz+BPzfgWhy87GHk0BVWdG bDFyd2EiOajXT353dt9HmP2De3rpoaK694V+um343Cg3nMsx0k4pNDsUybM2cVyf33HE fUDl0aGfS0DftFfvQSR3ediuriWOBq0nlUVVl55tGEDwOC6ZY3RZcSQfA/UeoFT4C9xy 6kyA== X-Received: by 10.180.79.40 with SMTP id g8mr19092012wix.3.1369264185946; Wed, 22 May 2013 16:09:45 -0700 (PDT) Received: from dft-labs.eu (n1x0n-1-pt.tunnel.tserv5.lon1.ipv6.he.net. [2001:470:1f08:1f7::2]) by mx.google.com with ESMTPSA id fp16sm13997492wic.6.2013.05.22.16.09.44 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 22 May 2013 16:09:44 -0700 (PDT) Date: Thu, 23 May 2013 01:09:40 +0200 From: Mateusz Guzik To: Noel Hunt Subject: Re: signal vs. sigaction and SIGCHLD Message-ID: <20130522230940.GA19960@dft-labs.eu> Mail-Followup-To: Mateusz Guzik , Noel Hunt , freebsd-hackers@freebsd.org References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) Cc: freebsd-hackers@freebsd.org X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 May 2013 23:09:47 -0000 On Thu, May 23, 2013 at 08:48:28AM +1000, Noel Hunt wrote: > I have a small test program which simply forks and execs > its command line arguments, but after the fork and before > the exec, it sends a SIGSTOP to the child. The parent then > sleeps for 3 seconds before exiting. However, a signal > handler for SIGCHLD has been installed and I was expecting > the parent to be notified of the SIGSTOP sent to the child, > but with the `signal' interface this doesn't appear to work. > > If I change the code to use `sigaction' and `sigprocmask' > (to unblock any blocked SIGCHLD), this program works the > way intended, that is, the signal handler is called: > > 12 static void waithandler(int i){ > 13 int pid, cursig; > 14 int tstat; > 15 > 16 #ifdef SIGACTION > 17 pid = waitpid(-1, &tstat, WUNTRACED); > 18 #else > 19 pid = wait(&tstat); > 20 signal(SIGCHLD, waithandler); You wait differently in case both cases. wait(2) waits for any child to exit, which clearly is not happening here. If you perform the same waitpid in both cases it should work fine. > If I recompile with `#undef SIGACTION', waithandler is not > called. > As noted earlier it is called. You can easly check that by printfing something at the beginning. > I should add that even with the sigaction(2) interface, without > the `sigprocmask' call, it still doesn't work, which suggests > that SIGCHLD is being blocked. > It could be that inherited signal mask blocks it. -- Mateusz Guzik