From owner-freebsd-threads@FreeBSD.ORG Mon Jun 28 21:19:59 2010 Return-Path: Delivered-To: threads@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id CDA441065673 for ; Mon, 28 Jun 2010 21:19:59 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id 9F91C8FC17 for ; Mon, 28 Jun 2010 21:19:59 +0000 (UTC) Received: from bigwig.baldwin.cx (66.111.2.69.static.nyinternet.net [66.111.2.69]) by cyrus.watson.org (Postfix) with ESMTPSA id 5576546B03; Mon, 28 Jun 2010 17:19:59 -0400 (EDT) Received: from jhbbsd.localnet (smtp.hudson-trading.com [209.249.190.9]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 90CBC8A03C; Mon, 28 Jun 2010 17:19:53 -0400 (EDT) From: John Baldwin To: Kostik Belousov Date: Mon, 28 Jun 2010 17:19:44 -0400 User-Agent: KMail/1.12.1 (FreeBSD/7.3-CBSD-20100217; KDE/4.3.1; amd64; ; ) References: <201006280833.54224.jhb@freebsd.org> <201006281444.50021.jhb@freebsd.org> <20100628191619.GF13238@deviant.kiev.zoral.com.ua> In-Reply-To: <20100628191619.GF13238@deviant.kiev.zoral.com.ua> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Message-Id: <201006281719.44236.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.0.1 (bigwig.baldwin.cx); Mon, 28 Jun 2010 17:19:53 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.95.1 at bigwig.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-2.6 required=4.2 tests=AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on bigwig.baldwin.cx Cc: threads@freebsd.org Subject: Re: SIGPIPE and threads X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Jun 2010 21:20:00 -0000 On Monday 28 June 2010 3:16:19 pm Kostik Belousov wrote: > On Mon, Jun 28, 2010 at 02:44:49PM -0400, John Baldwin wrote: > > On Monday 28 June 2010 10:05:34 am Kostik Belousov wrote: > > > On Mon, Jun 28, 2010 at 08:33:54AM -0400, John Baldwin wrote: > > > > Currently when a thread performs a write(2) on a disconnected socket or a FIFO > > > > with no readers the SIGPIPE signal is posted to the entire process via > > > > psignal(). This means that the signal can be delivered to any thread in the > > > > process. However, it seems more intuitive to me that SIGPIPE should be sent > > > > to the "offending" thread similar to signals sent in response to traps via > > > > trapsignal(). POSIX seems to require this in that the description of the > > > > EPIPE error return value for write(2) and fflush(3) in the Open Group's online > > > > manpages both say that SIGPIPE should be sent to the current thread in > > > > addition to returning EPIPE: > > > > > > > > http://www.opengroup.org/onlinepubs/000095399/functions/write.html > > > > > > > > http://www.opengroup.org/onlinepubs/000095399/functions/fflush.html > > > > > > > > I have an untested (only compiled) patch below: > > > > > > I think the patch is right, but, as you note, having a dedicated > > > function that wraps automatic ksi initialization and tdsignal() > > > call would be even better. > > > > Ok, what I've done is to rename tdsignal() to tdsendsignals() and make it > > private to kern_sig.c. I then added 'tdsignal()' and 'tdksignal()' to the > > public KPI to mirror the existing psignal() and pksignal() routines. > > > > This patch can be found at http://www.freebsd.org/~jhb/patches/tdsignal.patch > > It seems that tdsendsignal() call in trapsignal() can be replaced by > tdksignal(), unless I am mistaken. The same for psignal_event(). psignal_event() can't switch due to the !SIGEV_THREAD_ID case. For trapsignal() it could go either way. I sort of like having the 'p' argument passed to tdsendsignal() since we set p_code and p_sig just above the call. > There is also a reference to tdsignal() in subr_sleepqueue.c comment, > that is probably better to replace with tdsendsignal(). Good catch, fixed. > > I then reworked the sigpipe patch to just convert > > calls to psignal() to tdsignal() instead. It is at > > http://www.freebsd.org/~jhb/patches/sigpipe.patch > > Looks good. I'll write a regression test for this first, and once I'm happy with that I will commit. -- John Baldwin