cvs commit: src/sys/sys socketvar.h
Peter Jeremy
peterjeremy at optushome.com.au
Tue Jul 3 19:52:30 UTC 2007
On 2007-Jul-03 10:14:13 +0000, Robert Watson <rwatson at freebsd.org> wrote:
> Fix a bug in sblock() that has existed since revision 1.1 from BSD:
> correctly return an error if M_NOWAIT is passed to sblock() and the
> operation might block. This remarkably subtle macro bug appears to
> be responsible for quite a few undiagnosed socket buffer corruption
> and mbuf-related kernel panics.
This bug would appear to be a classic example of the dangers of trying
to force force multiple C statements into a single statement. IMHO,
it (and many of the other macros in socketvar.h) should be inline
functions, rather than macros.
IMHO, the following is far more legible:
static __inline int
sblock(struct sockbuf *sb, int wf)
{
if (sb->sb_flags & SB_LOCK)
return ((wf == M_WAITOK) ? sb_lock(sb) : EWOULDBLOCK);
else {
sb->sb_flags |= SB_LOCK;
return (0);
}
}
--
Peter Jeremy
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/cvs-src/attachments/20070703/e536bd47/attachment.pgp
More information about the cvs-src
mailing list