Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2008-05-17 10:34:32 +0200
committerArthur de Jong <arthur@arthurdejong.org>2008-05-17 10:34:32 +0200
commit24c144ff6033f1c8691300f00c2037018cda6ee5 (patch)
treec71bb4133b971506bad4507fe76d7f8c47a2be1a
parent088ad03574ddfa2ce836d91fbbec376e42810df3 (diff)
use send() with a flag to ignore SIGPIPE instead of write() so we don't have to muck with signal handlers
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-ldapd@740 ef36b2f9-881f-0410-afb5-c4e39611909c
-rw-r--r--common/tio.c18
1 files changed, 3 insertions, 15 deletions
diff --git a/common/tio.c b/common/tio.c
index 4f8c913..d52e0a6 100644
--- a/common/tio.c
+++ b/common/tio.c
@@ -29,6 +29,7 @@
#include <unistd.h>
#include <sys/time.h>
#include <sys/types.h>
+#include <sys/socket.h>
#include <errno.h>
#include <string.h>
#include <signal.h>
@@ -231,6 +232,7 @@ int tio_read(TFILE *fp, void *buf, size_t count)
/* have a more convenient storage type for the buffer */
uint8_t *ptr=(uint8_t *)buf;
/* build a time by which we should be finished */
+ /* TODO: probably only set up deadline if we have to do select() */
tio_tv_prepare(&deadline,&(fp->readtimeout));
/* loop until we have returned all the needed data */
while (1)
@@ -315,22 +317,8 @@ int tio_skip(TFILE *fp, size_t count)
static int tio_writebuf(TFILE *fp)
{
int rv;
- struct sigaction act,oldact;
- /* FIXME: we have a race condition here (setting and restoring the signal mask), this is a critical region that should be locked */
- /* 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 */
+ rv=send(fp->fd,fp->writebuffer.buffer+fp->writebuffer.start,fp->writebuffer.len,MSG_NOSIGNAL);
/* check for errors */
if ((rv==0)||((rv<0)&&(errno!=EINTR)&&(errno!=EAGAIN)))
return -1; /* something went wrong with the write */