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 [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to