Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 02 Jan 2003 15:04:30 -0800
From:      Tim Kientzle <kientzle@acm.org>
To:        Terry Lambert <tlambert2@mindspring.com>
Cc:        wgrim@siue.edu, phk@FreeBSD.ORG, freebsd-hackers@FreeBSD.ORG
Subject:   Re: Reading rc.conf from C programs?
Message-ID:  <3E14C57E.3060304@acm.org>
References:  <4351.1041538966@critter.freebsd.dk> <1041540674.3e14a642d30b5@webmail1.isg.siue.edu> <3E14B087.EC43701B@mindspring.com>

next in thread | previous in thread | raw e-mail | index | archive | help
So far, it sounds like noone has actually implemented
a completely robust way to read rc.conf data into a
shell program, although a lot of people have had good
experiences with simple variable=value parsing of the
raw files.

PHK's idea (use 'set' to dump the shell vars before and
after sourcing rc.conf) is pretty close, but can be
fooled by the following (admittedly pathalogical) example:
    a='b
    c=d'

However, I had missed 'set -a'; that just might
solve the problem completely, while still supporting
arbitrary shell code:

* Use popen() to capture the output of the
   following script:
     #!/bin/sh
     set -a
     if [ -r /etc/defaults/rc.conf ]; then
       . /etc/defaults/rc.conf
       source_rc_confs
     elif [ -r /etc/rc.conf ]; then
       . /etc/rc.conf
     fi
     my_custom_printenv

* my_custom_printenv is a C program like /usr/bin/printenv,
   but it encodes newlines, etc, so that the text output
   is unambiguous (the stock printenv generates ambiguous
   output from examples like the one above)

* capture and decode the output in the main program;
   discard anything that's present in the main program's
   environment.

Can anyone see any way that this could fail?  This
would certainly be _much_ simpler than the approaches
I had originally envisioned.  Thanks for everyone's input!

Tim Kientzle


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3E14C57E.3060304>