Subject: Re: dynamic sysctl
To: Andrew Brown <atatat@atatdot.net>
From: David Laight <david@l8s.co.uk>
List: tech-kern
Date: 11/17/2003 22:43:14
On Mon, Nov 17, 2003 at 04:08:57PM -0500, Andrew Brown wrote:
> >> >Why not just make:
> >> >	sysctl((void *)"kern.maxproc", 0, &buf, sizeof buf, NULL, 0);
> >> >return the value of kern.maxproc (etc).
> >> 
> >> sounds nice, but how does that communicate the type of the returned
> >> data to the caller?  or maybe buf could then consist of a type number,
> >> followed by a length number, followed by the actual data...
> >
> >Well, in most cases (ie everything except the sysctl program) the
> >caller knows what he expects. For sysctl maybe "kern.?" could return
> >the types of the subfields
> >- better have 'kern.*' return "name:type.name:type"
> 
> and...in most cases (ie, everything except the sysctl program) the
> caller knows where the thing is that he's looking for, and does not
> have to do auto-discovery.

Except that it is safer to use the kernel's map of name => number, rather
than have some programs using the kernel's map and others the header
file.  Especially if you don't know whether the item has a fixed name
or a dynamic one.

The run-time cost in cpu cycles should be trivial. From a coding point
of view sysctl_read("kern.maxproc", &buf, sizeof buf) would be less
error prone than the current scheme.

Maybe, in time, the numbers could be depracated....

	David

-- 
David Laight: david@l8s.co.uk