Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 17 Aug 2005 11:01:49 +1000 (EST)
From:      Bruce Evans <bde@zeta.org.au>
To:        Pawel Jakub Dawidek <pjd@freebsd.org>
Cc:        m.ehinger@ltur.de, freebsd-arch@freebsd.org
Subject:   Re: sysctl_proc calls handler twice
Message-ID:  <20050817104144.L1361@epsplex.bde.org>
In-Reply-To: <20050816133307.GD3944@garage.freebsd.pl>
References:  <OF28F4B4F7.07CB26A2-ONC125705E.00222E3B-C125705E.00226191@gateway-inter.net> <20050816221033.C47830@delplex.bde.org> <20050816133307.GD3944@garage.freebsd.pl>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 16 Aug 2005, Pawel Jakub Dawidek wrote:

> On Tue, Aug 16, 2005 at 11:17:21PM +1000, Bruce Evans wrote:
> +> No, just don't call it twice like sysctl(8) if you know the size in advance
> +> or from a previous call (and know that it won't change or handle the error
> +> from it changing...).
>
> Thread's author, as I understand/guess it, represents kernel side.
> He doesn't want his handler to be called twice and tools like sysctl(8)
> are not able to know size of every sysctl, so he just has to be ready
> that his handler will be called twice.

[It turned out to be a race problem]

Well, any handler may be called any number of times in any order,
including possibly concurrently.  All sysctls are still Giant-locked
so concurent calls can't actually happen, but making a separate call
to determine the size gives races anyway if the size can change.
Applications should loop if the size that they got turns out to be
insufficent.  sysctl(8) doesn't do this -- it doubles the size but
doesn't retry.  Writing requires even more care.

Bruce



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