From owner-freebsd-hackers Thu Jan 2 12:19: 8 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 D155637B401 for ; Thu, 2 Jan 2003 12:19:06 -0800 (PST) Received: from clover.kientzle.com (user-112uh9a.biz.mindspring.com [66.47.69.42]) by mx1.FreeBSD.org (Postfix) with ESMTP id D2A2C43EA9 for ; Thu, 2 Jan 2003 12:19:04 -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 h02KItE34859; Thu, 2 Jan 2003 12:18:56 -0800 (PST) (envelope-from kientzle@acm.org) Message-ID: <3E149EAF.9040100@acm.org> Date: Thu, 02 Jan 2003 12:18:55 -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: Terry Lambert Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: Reading rc.conf from C programs? References: <3E1362FD.6070001@acm.org> <3E13CCF1.FA78AD5D@mindspring.com> 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 Terry Lambert wrote: > Tim Kientzle wrote: >>I'm trying to figure out how to read and use >>/etc/rc.conf configuration variables from within >>a C program. > > #!/bin/sh > # Throw all of rc.conf into the environemnet so a C program > # named "fred" can read any of them with "getenv". > . /etc/rc.conf > fred This doesn't work. /etc/rc.conf does not export its variables to the environment. It only sets them in the local shell. Try the above where 'fred' is #!/bin/sh printenv and you'll see what I mean. >>Has anyone done anything like this before? >> > > Yeah. fopen(3), for(;;) { fgets(3), strtok(3) } fclose(3). This is what 'thefish' and 'sysinstall' both do, more or less. Of course, this doesn't work in all cases. (Witness the last 20 lines or so of /etc/defaults/rc.conf to understand why this doesn't work.) rc.conf is _not_ a list of variable=value pairs. It is a shell script that sets a number of shell variables. Nothing less than a full-fledged implementation of /bin/sh is gauranteed to work in all cases. Which comes back to the question in my original posting: does anyone have sample code for manipulating a slave /bin/sh using popen? or, alternatively, has anyone modified /bin/sh to operate as an embedded interpreter? Tim Kientzle To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message