From owner-freebsd-hackers Wed Jan 1 13:52: 1 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 0852F37B406 for ; Wed, 1 Jan 2003 13:52:00 -0800 (PST) Received: from clover.kientzle.com (user-112uh9a.biz.mindspring.com [66.47.69.42]) by mx1.FreeBSD.org (Postfix) with ESMTP id 433CD43EB2 for ; Wed, 1 Jan 2003 13:51:59 -0800 (PST) (envelope-from kientzle@acm.org) Received: from acm.org (c43 [66.47.69.43]) by clover.kientzle.com (8.11.3/8.11.3) with ESMTP id h01LpvE32537 for ; Wed, 1 Jan 2003 13:51:58 -0800 (PST) (envelope-from kientzle@acm.org) Message-ID: <3E1362FD.6070001@acm.org> Date: Wed, 01 Jan 2003 13:51:57 -0800 From: Tim Kientzle Reply-To: kientzle@acm.org User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:0.9.6) Gecko/20011206 X-Accept-Language: en-us, en MIME-Version: 1.0 To: freebsd-hackers@FreeBSD.ORG Subject: Reading rc.conf from C programs? Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit 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 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