Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 4 Jul 2007 05:52:28 +1000
From:      Peter Jeremy <peterjeremy@optushome.com.au>
To:        Robert Watson <rwatson@freebsd.org>
Cc:        cvs-src@freebsd.org, src-committers@freebsd.org, cvs-all@freebsd.org
Subject:   Re: cvs commit: src/sys/sys socketvar.h
Message-ID:  <20070703195228.GP15680@turion.vk2pj.dyndns.org>
In-Reply-To: <200707031014.l63AEE9Y026819@repoman.freebsd.org>
References:  <200707031014.l63AEE9Y026819@repoman.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help

--pE2VAHO2njSJCslu
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On 2007-Jul-03 10:14:13 +0000, Robert Watson <rwatson@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 =3D=3D M_WAITOK) ? sb_lock(sb) : EWOULDBLOCK);
	else {
		sb->sb_flags |=3D SB_LOCK;
		return (0);
	}
}

--=20
Peter Jeremy

--pE2VAHO2njSJCslu
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (FreeBSD)

iD8DBQFGiqj8/opHv/APuIcRArpaAKC2NEu4WSZCp1SfpMQMZtZkeOyB6wCeNpKM
rLx8sl952WKNhYYL4aSercU=
=UNvf
-----END PGP SIGNATURE-----

--pE2VAHO2njSJCslu--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20070703195228.GP15680>