Date: Wed, 14 Apr 2004 17:14:54 -0700 From: Tim Kientzle <tim@kientzle.com> To: Craig Rodrigues <rodrigc@crodrigues.org> Cc: freebsd-hackers@freebsd.org Subject: Re: C code for parsing rc.conf? Message-ID: <407DD3FE.5010303@kientzle.com> In-Reply-To: <20040414215601.GA3923@crodrigues.org> References: <20040414215601.GA3923@crodrigues.org>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?407DD3FE.5010303>