Date: Fri, 19 Jan 2001 21:08:00 +0100 From: Poul-Henning Kamp <phk@critter.freebsd.dk> To: Kirk McKusick <mckusick@mckusick.com> Cc: Alfred Perlstein <bright@wintelcom.net>, arch@FreeBSD.ORG Subject: Re: dynamic vs static sysctls? Message-ID: <98602.979934880@critter> In-Reply-To: Your message of "Tue, 16 Jan 2001 15:06:18 PST." <200101162306.PAA23554@beastie.mckusick.com>
next in thread | previous in thread | raw e-mail | index | archive | help
In message <200101162306.PAA23554@beastie.mckusick.com>, Kirk McKusick writes:
>
> >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).
Looks good, commit it :-)
Poul-Henning
>
> 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);
>}
>
--
Poul-Henning Kamp | UNIX since Zilog Zeus 3.20
phk@FreeBSD.ORG | TCP/IP since RFC 956
FreeBSD committer | BSD since 4.3-tahoe
Never attribute to malice what can adequately be explained by incompetence.
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?98602.979934880>
