Loading...

freebsd-threads@freebsd.org

[Prev] Thread [Next]  |  [Prev] Date [Next]

Re: SIGPIPE and threads John Baldwin Mon Jun 28 15:01:04 2010

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
_______________________________________________
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-threads
To unsubscribe, send any mail to "[EMAIL PROTECTED]"