From owner-freebsd-hackers@FreeBSD.ORG Wed Apr 14 23:29:34 2004 Return-Path: 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 9E79D16A4CE for ; Wed, 14 Apr 2004 23:29:34 -0700 (PDT) Received: from bogslab.ucdavis.edu (bogslab.ucdavis.edu [169.237.68.34]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7B12D43D31 for ; Wed, 14 Apr 2004 23:29:34 -0700 (PDT) (envelope-from gkshenaut@ucdavis.edu) Received: from [198.137.203.49] (merlin.bogs.org [198.137.203.49]) by bogslab.ucdavis.edu (8.12.8/8.12.8) with ESMTP id i3F6TJDb034062; Wed, 14 Apr 2004 23:29:19 -0700 (PDT) In-Reply-To: <407DD3FE.5010303@kientzle.com> References: <20040414215601.GA3923@crodrigues.org> <407DD3FE.5010303@kientzle.com> Mime-Version: 1.0 (Apple Message framework v613) Content-Type: text/plain; charset=US-ASCII; format=flowed Message-Id: Content-Transfer-Encoding: 7bit From: Greg Shenaut Date: Wed, 14 Apr 2004 23:25:28 -0700 To: Tim Kientzle X-Mailer: Apple Mail (2.613) cc: freebsd-hackers@freebsd.org cc: Craig Rodrigues Subject: Re: C code for parsing rc.conf? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Apr 2004 06:29:34 -0000 On Apr 14, 2004, at 5:14 PM, Tim Kientzle wrote: > Craig Rodrigues wrote: >> Is there a C library that comes with FreeBSD which >> can be used to parse, append to, and validate >> rc.conf? >> I'd like to customize some of the settings in /etc/rc.conf >> with my own GUI-based program. It's not too hard >> to write something on my own, but I was wondering >> if a reusable library existed in FreeBSD 4.x or 5.x for doing this. > > There was a detailed discussion of this topic about a year > ago. Here is how to obtain the current settings from rc.conf > from within a C program: > > * Clear the current environment > > * popen() a shell command that sources rc.conf, then > runs printenv > > * read and parse the output of printenv > > The basic idea is to just let the shell do > the work for you. It's a little more awkward, but another way to do this is to use a shell shim along the lines of #!/bin/sh . /etc/whatever exec /your/program The shell's environment will be exported to your program's environment. Greg Shenaut