From owner-freebsd-current@FreeBSD.ORG Tue Jun 26 00:13:27 2012 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id A4E7F106566C; Tue, 26 Jun 2012 00:13:27 +0000 (UTC) (envelope-from yanegomi@gmail.com) Received: from mail-ob0-f182.google.com (mail-ob0-f182.google.com [209.85.214.182]) by mx1.freebsd.org (Postfix) with ESMTP id 211B58FC2B; Tue, 26 Jun 2012 00:13:24 +0000 (UTC) Received: by obbun3 with SMTP id un3so9218258obb.13 for ; Mon, 25 Jun 2012 17:13:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=HC4/mWNQSj8y7inIacE/Rtv6FSU3ix2/YnsbqqO5w4c=; b=e79oAgb3yXNLvwLvgrLvCfTTJE/qqv94Ji+ImorM+JLlY31t46mh7Q6g+PNsuWEzdD aeqJUFg8zdf+UqsYcl7dhqcpurhtXeiYMA+QFCTbrsWDk+TW3nJyPQOUI+QmnpHxdd47 RJcCJcC8lTG1vSSi4ZowzmaJ7SWcQu9W1XNiXxWS9KfCWWCXcUVTNaaeNRfUZ5KRfvfN uRJ9SOcoxtBe36qBa9fuESInq/OHb5zUX+tt8z/dOyheTT1EFLxm93kTpIh9IEdHKvAo v5e/sQ2VF5Uv8/BhHjTdJBEIYcOIamHlJZ/GjjtO+ofGGJaEVbXKElvWEEMyDwGbMJln BiUQ== MIME-Version: 1.0 Received: by 10.60.20.136 with SMTP id n8mr3891674oee.54.1340669603645; Mon, 25 Jun 2012 17:13:23 -0700 (PDT) Received: by 10.76.95.194 with HTTP; Mon, 25 Jun 2012 17:13:23 -0700 (PDT) In-Reply-To: References: Date: Mon, 25 Jun 2012 17:13:23 -0700 Message-ID: From: Garrett Cooper To: Arnaud Lacombe Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: FreeBSD Hackers , FreeBSD Current , kby@freebsd.org, bp@freebsd.org Subject: Re: sysctl filesystem ? X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Jun 2012 00:13:27 -0000 On Mon, Jun 25, 2012 at 5:03 PM, Arnaud Lacombe wrote: > Hi folks, > > I find myself in a situation where I need to directly explore the > sysctl(8) tree from my program. The tricky part is this: > > from `src/sbin/sysctl.c': > /* > =A0* These functions uses a presently undocumented interface to the kerne= l > =A0* to walk the tree and get the type so it can print the value. > =A0* This interface is under work and consideration, and should probably > =A0* be killed with a big axe by the first person who can find the time. > =A0* (be aware though, that the proper interface isn't as obvious as it > =A0* may seem, there are various conflicting requirements. > =A0*/ > > AFAIT, the whole interface used by sysctl(8) to explore the sysctl > tree (ie. list, name, get description) is undocumented. This comment > has been there for about, well... 17 years. No matter to say that it > is highly unlikely anyone is ever gonna design that perfect interface. > Right now, I am left with no choice but to figure out how that stuff > work, which I foresee will be a real PITA. No choice ? Well, not so > much. About 12 years ago a filesystem interface was written for > sysctl, namely scfs(4). It was authored by Kelly Yancey and (?) Boris > Popov. Unfortunately, time passed and no code is any longer publicly > available. URLs are either no longer valid or password-protected. > > This interface would just be perfect for my use-case. No need to spend > time decoding a prehistoric interface, no need to craft custom > accessors. I would just have to use standard POSIX file interface... > if the code was available. > > I was hoping some of the people on this list would either, have the > scfs(4) code on their drives/tapes, or have a way to contact the > original author(s) and thus have a chance to get that code ? > > Thanks in advance, > =A0- Arnaud > > ps: I know the code will certainly have to be fixed, but that is still > the best option I've got so far. Alternatively, the interface could just be documented (from sys/kern/kern_sysctl.c): /* * "Staff-functions" * * These functions implement a presently undocumented interface * used by the sysctl program 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. * * {0,0} printf the entire MIB-tree. * {0,1,...} return the name of the "..." OID. * {0,2,...} return the next OID. * {0,3} return the OID of the name in "new" * {0,4,...} return the kind & format info for the "..." OID. * {0,5,...} return the description the "..." OID. */ I know 2 closed-source versions that have wholesale stolen/"borrowed" the code from sysctl(3), and I adapted the sysctl(8) code for my own uses for the cython derivative I made here [1]. Thanks, -Garrett 1. http://sourceforge.net/projects/sysctl/