From owner-freebsd-hackers Wed Jan 1 20:22:52 2003 Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6742137B407 for ; Wed, 1 Jan 2003 20:22:46 -0800 (PST) Received: from jkh-gw.queasyweasel.com (adsl-64-173-3-158.dsl.sntc01.pacbell.net [64.173.3.158]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6724543ED8 for ; Wed, 1 Jan 2003 20:22:45 -0800 (PST) (envelope-from jkh@queasyweasel.com) Received: from queasyweasel.com (narcissus.freebsd.com [64.173.15.99]) by jkh-gw.queasyweasel.com (8.12.6/8.12.5) with ESMTP id h024M7XW076069; Wed, 1 Jan 2003 20:22:08 -0800 (PST) (envelope-from jkh@queasyweasel.com) Date: Wed, 1 Jan 2003 20:23:00 -0800 Subject: Re: Reading rc.conf from C programs? Content-Type: text/plain; charset=US-ASCII; format=flowed Mime-Version: 1.0 (Apple Message framework v551) Cc: freebsd-hackers@FreeBSD.ORG To: kientzle@acm.org From: Jordan K Hubbard In-Reply-To: <3E1362FD.6070001@acm.org> Message-Id: Content-Transfer-Encoding: 7bit X-Mailer: Apple Mail (2.551) Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG There's no canned code for doing this, though sysinstall has some very basic parsing routines for reading/writing rc.conf variables you could certain crib from. It sounds like that "thefish" utility someone else mentioned has an even more exotic parser, though I haven't compared the two implementations. The readConfigFile() routine in sysinstall simply reads the configuration data into a fixed-size array, so it's pretty braindead. - Jordan On Wednesday, January 1, 2003, at 01:51 PM, Tim Kientzle wrote: > I'm trying to figure out how to read and use > /etc/rc.conf configuration variables from within > a C program. The standard technique, of course, > is to use a shell-script wrapper and pass the > extracted values to the C program on the command > line. But I want access to _all_ of the rc.conf > variables, not just a couple of them, and I don't > see any reasonable way to accomplish that with a > shell wrapper. > > One approach would embed /bin/sh and drive that > from my program. (E.g., tell the embedded interpreter > to read and interpret the config file, then > programmatically query the config variables.) > It's not clear to me how simple it would be to > build an embeddable /bin/sh. > > Alternatively, I suppose I could fire up /bin/sh via > popen and drive it from my program (passing 'echo $var' > to query variables, etc.). But I'm not entirely > convinced this would work; what if a variable value has > a newline in it, for example? > > Has anyone done anything like this before? > > Thanks, > > Tim Kientzle > > > To Unsubscribe: send mail to majordomo@FreeBSD.org > with "unsubscribe freebsd-hackers" in the body of the message > -- Jordan K. Hubbard Engineering Manager, BSD technology group Apple Computer To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message