From owner-freebsd-arch Tue Jan 16 15: 9:45 2001 Delivered-To: freebsd-arch@freebsd.org Received: from beastie.mckusick.com (machine.qwest.net [204.154.239.5]) by hub.freebsd.org (Postfix) with ESMTP id 3E23537B400 for ; Tue, 16 Jan 2001 15:09:25 -0800 (PST) Received: from beastie.mckusick.com (localhost [127.0.0.1]) by beastie.mckusick.com (8.9.3/8.9.3) with ESMTP id PAA23554; Tue, 16 Jan 2001 15:06:18 -0800 (PST) (envelope-from mckusick@beastie.mckusick.com) Message-Id: <200101162306.PAA23554@beastie.mckusick.com> To: Poul-Henning Kamp Subject: Re: dynamic vs static sysctls? Cc: Alfred Perlstein , arch@FreeBSD.ORG In-Reply-To: Your message of "Tue, 16 Jan 2001 08:11:50 +0100." <43114.979629110@critter> Date: Tue, 16 Jan 2001 15:06:18 -0800 From: Kirk McKusick Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG To: Kirk McKusick 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 >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 #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); } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message