From owner-freebsd-hackers@FreeBSD.ORG Wed Apr 14 17:15:04 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 0968F16A4CE for ; Wed, 14 Apr 2004 17:15:04 -0700 (PDT) Received: from kientzle.com (h-66-166-149-50.snvacaid.covad.net [66.166.149.50]) by mx1.FreeBSD.org (Postfix) with ESMTP id E793343D2D for ; Wed, 14 Apr 2004 17:15:02 -0700 (PDT) (envelope-from tim@kientzle.com) Received: from kientzle.com (p54.kientzle.com [66.166.149.54]) by kientzle.com (8.12.9/8.12.9) with ESMTP id i3F0Es90032428; Wed, 14 Apr 2004 17:14:54 -0700 (PDT) (envelope-from tim@kientzle.com) Message-ID: <407DD3FE.5010303@kientzle.com> Date: Wed, 14 Apr 2004 17:14:54 -0700 From: Tim Kientzle User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.4) Gecko/20031006 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Craig Rodrigues References: <20040414215601.GA3923@crodrigues.org> In-Reply-To: <20040414215601.GA3923@crodrigues.org> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit cc: freebsd-hackers@freebsd.org 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 00:15:04 -0000 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. You can make this process a bit more predictable by using a modified printenv that dumps variable names and values in hex or something similar. (Or, submit a patch to the existing printenv.) To update rc.conf, just append new statements to the end of the file. Don't try to edit it in place. Later variable settings will override earlier ones, so this will have the expected result without possibly trashing someone's custom shell scripting. I may have overlooked a few details, but this should be enough to get you started. Tim Kientzle