Date: Thu, 02 Jan 2003 12:18:55 -0800 From: Tim Kientzle <kientzle@acm.org> To: Terry Lambert <tlambert2@mindspring.com> Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: Reading rc.conf from C programs? Message-ID: <3E149EAF.9040100@acm.org> References: <3E1362FD.6070001@acm.org> <3E13CCF1.FA78AD5D@mindspring.com>
index | next in thread | previous in thread | raw e-mail
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
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3E149EAF.9040100>
