[Date Prev][Date Next] [Chronological] [Thread] [Top]

SIGPIPE (again)



Hello,

I've been dealing w/ random programs crashing when the get
SIGPIPE working it's way up from liblber->libldap->nss_ldap->etc
(I use ldap as my nsswitch source).

I see this has come up before, on Wed, 3 Apr 2002 Igor Brezac wrote:

> I do not think that this is a bug because the socket can brake between the
> test and the write() call.  I tried several different ldap libs and they
> behave the same in this particular example.  The application needs to take
> care of this with something simple like signal(SIGPIPE, SIG_IGN).


This strategy won't work here, since pretty much every program could
get the SIGPIPE.

The general solution to this is for every OS to do the right thing and
deliver SIGPIPE to the _thread_ that caused it.  But, in the mean time
on linux at least, there is another way.  You can use send() instead
of write, and add MSG_NOSIGNAL to the flags:

       MSG_NOSIGNAL
              This  flag  turns  off raising of SIGPIPE on stream sockets when
              the other end disappears.


I have patched my openldap to add a test for linux and define 
tcp_write/tcp_read to use send/recv w/ MSG_NOSIGNAL set, and then to
fix the two places that call read/write directly to use tcp_write/tcp_read.

Would this solution be generally acceptable to the openldap team?

-Seth