Date: Tue, 16 Jan 2001 15:06:18 -0800 From: Kirk McKusick <mckusick@mckusick.com> To: Poul-Henning Kamp <phk@critter.freebsd.dk> Cc: Alfred Perlstein <bright@wintelcom.net>, arch@FreeBSD.ORG Subject: Re: dynamic vs static sysctls? Message-ID: <200101162306.PAA23554@beastie.mckusick.com> In-Reply-To: Your message of "Tue, 16 Jan 2001 08:11:50 %2B0100." <43114.979629110@critter>
next in thread | previous in thread | raw e-mail | index | archive | help
To: Kirk McKusick <mckusick@mckusick.com>
Subject: Re: dynamic vs static sysctls?
In-Reply-To: Your message of "Mon, 15 Jan 2001 15:45:35 PST."
<200101152345.PAA22257@beastie.mckusick.com>
Date: Tue, 16 Jan 2001 08:11:50 +0100
From: Poul-Henning Kamp <phk@critter.freebsd.dk>
>I want
>to do one call to sysctlnametomib (a new, but obviously trivial
>function) to return the numeric mib, and then use that mib on all
>the subsequent sysctl calls.
As new-sysctl "designer" I think this is a good idea. It's a trivial
thing to implement, so are there any warm and able bodies who want
to try their hands at it and send the patch to me for review ?
--
Poul-Henning Kamp | UNIX since Zilog Zeus 3.20
phk@FreeBSD.ORG | TCP/IP since RFC 956
FreeBSD committer | BSD since 4.3-tahoe
Here is my proposal (along with a test program for it).
Kirk
=-=-=-=-=-=-=-=-=
#include <sys/types.h>
#include <sys/sysctl.h>
int sysctlnametomib __P((char *name, int *oidp, size_t *sizep));
/*
* This function uses a presently undocumented interface to the kernel
* to walk the tree and get the type so it can print the value.
* This interface is under work and consideration, and should probably
* be killed with a big axe by the first person who can find the time.
* (be aware though, that the proper interface isn't as obvious as it
* may seem, there are various conflicting requirements.
*/
int
sysctlnametomib(char *name, int *oidp, size_t *sizep)
{
int oid[2];
int error;
oid[0] = 0;
oid[1] = 3;
*sizep *= sizeof (int);
error = sysctl(oid, 2, oidp, sizep, name, strlen(name));
*sizep /= sizeof (int);
if (error < 0)
return (error);
return (0);
}
/*
* Test program for sysctlnametomib.
*
* Usage: sysctlnametomib name
*/
main(ac, av)
int ac;
char *av[];
{
int i, mib[CTL_MAXNAME];
size_t size;
if (ac < 2) {
printf("Usage: %s name\n", av[0]);
exit(1);
}
size = CTL_MAXNAME;
if (sysctlnametomib(av[1], mib, &size) < 0) {
perror("sysctlnametomib");
exit(1);
}
for (i = 0; i < size; i++)
printf("mib[%d] = %d\n", i, mib[i]);
exit(0);
}
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200101162306.PAA23554>
