Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2008-06-12 23:38:22 +0200
committerArthur de Jong <arthur@arthurdejong.org>2008-06-12 23:38:22 +0200
commit0d860441e3ff58b4faa033073235ad9c3b9a87c7 (patch)
treeaf8878f19e727d3b41647b73532f61f93e5a3524 /common
parent335553af0d1208bf66173608ad55ebe799474fcf (diff)
restore the old writing code which masks SIGPIPE on platforms that can't use send()
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-ldapd@758 ef36b2f9-881f-0410-afb5-c4e39611909c
Diffstat (limited to 'common')
-rw-r--r--common/tio.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/common/tio.c b/common/tio.c
index d52e0a6..0821f90 100644
--- a/common/tio.c
+++ b/common/tio.c
@@ -318,7 +318,28 @@ static int tio_writebuf(TFILE *fp)
{
int rv;
/* write the buffer */
+#ifdef MSG_NOSIGNAL
rv=send(fp->fd,fp->writebuffer.buffer+fp->writebuffer.start,fp->writebuffer.len,MSG_NOSIGNAL);
+#else /* not MSG_NOSIGNAL */
+ /* on platforms that cannot use send() with masked signals, we change the
+ signal mask and change it back after the write (note that there is a
+ race condition here) */
+ struct sigaction act,oldact;
+ /* set up sigaction */
+ memset(&act,0,sizeof(struct sigaction));
+ act.sa_sigaction=NULL;
+ act.sa_handler=SIG_IGN;
+ sigemptyset(&act.sa_mask);
+ act.sa_flags=SA_RESTART;
+ /* ignore SIGPIPE */
+ if (sigaction(SIGPIPE,&act,&oldact)!=0)
+ return -1; /* error setting signal handler */
+ /* write the buffer */
+ rv=write(fp->fd,fp->writebuffer.buffer+fp->writebuffer.start,fp->writebuffer.len);
+ /* restore the old handler for SIGPIPE */
+ if (sigaction(SIGPIPE,&oldact,NULL)!=0)
+ return -1; /* error restoring signal handler */
+#endif
/* check for errors */
if ((rv==0)||((rv<0)&&(errno!=EINTR)&&(errno!=EAGAIN)))
return -1; /* something went wrong with the write */