From owner-freebsd-hackers@FreeBSD.ORG Thu Apr 15 10:06:35 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 A323916A4CE for ; Thu, 15 Apr 2004 10:06:35 -0700 (PDT) Received: from thunder.nws.noaa.gov (fs1-nhdw.nws.noaa.gov [140.90.90.97]) by mx1.FreeBSD.org (Postfix) with ESMTP id 220B643D55 for ; Thu, 15 Apr 2004 10:06:35 -0700 (PDT) (envelope-from ash.gokhale@noaa.gov) Received: from [192.168.0.66] (hel [140.90.90.7])ESMTP id RAA17305 for ; Thu, 15 Apr 2004 17:06:33 GMT Mime-Version: 1.0 (Apple Message framework v613) In-Reply-To: <407DD3FE.5010303@kientzle.com> References: <20040414215601.GA3923@crodrigues.org> <407DD3FE.5010303@kientzle.com> Content-Type: text/plain; charset=US-ASCII; format=flowed Message-Id: <3DFA0E20-8EFF-11D8-AF6E-00039383C51E@noaa.gov> Content-Transfer-Encoding: 7bit From: Ash Gokhale Date: Thu, 15 Apr 2004 13:06:31 -0400 To: freebsd-hackers@freebsd.org X-Mailer: Apple Mail (2.613) X-Mailman-Approved-At: Fri, 16 Apr 2004 05:09:11 -0700 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 17:06:35 -0000 I'll give you another 'easy' hack to contemplate. 6 == 12 * 0,5 Make your tool system('sh /etc/rc.conf'); And then use the native [get|set]env(3) functions to read/write the values you are intested in. When you are ready to commit the process scan **environ (7) to rebuild it without the redundant stuff (and without your uid env). I think it's much better to use the shells logic rather than parsing. There may be installations that require a little math or early reentrant shell programming to manage startup. What ever you do _pleese_ offer automatic failback to the previous rc.conf if the system comes up sour with the generated rc. Perhaps this should be hooks to rc itself. Has anyone used SystemStarter under FreeBSD? It can really haul a machine through the startup sequence by parallel execution of non critical startup binaries. I've seen it pull an otherwise sluggish darwin up in a big hurry. On Apr 14, 2004, at 8: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? > > 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. > > Ash.Gokhale@noaa.gov System Administration Lead, NOAA/MDL