From owner-freebsd-hackers Thu Jan 2 15: 4:40 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 C707937B401; Thu, 2 Jan 2003 15:04:38 -0800 (PST) Received: from clover.kientzle.com (user-112uh9a.biz.mindspring.com [66.47.69.42]) by mx1.FreeBSD.org (Postfix) with ESMTP id CC1C843E4A; Thu, 2 Jan 2003 15:04:37 -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 h02N4YE35479; Thu, 2 Jan 2003 15:04:34 -0800 (PST) (envelope-from kientzle@acm.org) Message-ID: <3E14C57E.3060304@acm.org> Date: Thu, 02 Jan 2003 15:04:30 -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: wgrim@siue.edu, phk@FreeBSD.ORG, freebsd-hackers@FreeBSD.ORG Subject: Re: Reading rc.conf from C programs? References: <4351.1041538966@critter.freebsd.dk> <1041540674.3e14a642d30b5@webmail1.isg.siue.edu> <3E14B087.EC43701B@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 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