diff options
author | Henning Brauer <henning@cvs.openbsd.org> | 2004-08-17 15:59:35 +0000 |
---|---|---|
committer | Henning Brauer <henning@cvs.openbsd.org> | 2004-08-17 15:59:35 +0000 |
commit | 4a3db94e9fd4fdc7f702554b46b4aac260f62c1a (patch) | |
tree | 5cb79611594a7eee788e5f842ee2964324585e17 | |
parent | 4b6e856615cb5509d01b2125b02520674eb655cd (diff) |
when sending a file descriptor, close it on the receiving side in
buf_dequeue() instead of in msgbuf_write(). as sendmsg() might return
without having written all data (we're on nonblocking sockets), we
might have closed the fd before it actually got send.
tracked down after (completely independent, didn't even look related at all)
bug reports from Shaun O'Neil <shaun@dma.nl> and
Arvid Grtting <arvidg@netfonds.no>, claudio ok
-rw-r--r-- | usr.sbin/bgpd/buffer.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/usr.sbin/bgpd/buffer.c b/usr.sbin/bgpd/buffer.c index 6887b793a59..b670d69c6eb 100644 --- a/usr.sbin/bgpd/buffer.c +++ b/usr.sbin/bgpd/buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buffer.c,v 1.22 2004/07/03 17:19:59 claudio Exp $ */ +/* $OpenBSD: buffer.c,v 1.23 2004/08/17 15:59:34 henning Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -183,9 +183,6 @@ msgbuf_write(struct msgbuf *msgbuf) return (-2); } - if (buf != NULL && buf->fd != -1) - close(buf->fd); - for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; buf = next) { next = TAILQ_NEXT(buf, entry); @@ -251,6 +248,10 @@ void buf_dequeue(struct msgbuf *msgbuf, struct buf *buf) { TAILQ_REMOVE(&msgbuf->bufs, buf, entry); + + if (buf->fd != -1) + close(buf->fd); + msgbuf->queued--; buf_free(buf); } |