From owner-freebsd-arch Fri Jan 19 12: 8:34 2001 Delivered-To: freebsd-arch@freebsd.org Received: from critter.freebsd.dk (flutter.freebsd.dk [212.242.40.147]) by hub.freebsd.org (Postfix) with ESMTP id C225837B400 for ; Fri, 19 Jan 2001 12:08:10 -0800 (PST) Received: from critter (localhost [127.0.0.1]) by critter.freebsd.dk (8.11.1/8.11.1) with ESMTP id f0JK80l98604; Fri, 19 Jan 2001 21:08:05 +0100 (CET) (envelope-from phk@critter.freebsd.dk) To: Kirk McKusick Cc: Alfred Perlstein , arch@FreeBSD.ORG Subject: Re: dynamic vs static sysctls? In-Reply-To: Your message of "Tue, 16 Jan 2001 15:06:18 PST." <200101162306.PAA23554@beastie.mckusick.com> Date: Fri, 19 Jan 2001 21:08:00 +0100 Message-ID: <98602.979934880@critter> From: Poul-Henning Kamp Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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 >#include > >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