Skip site navigation (1)Skip section navigation (2)
Date:      Thu,  2 Jan 2003 14:51:14 -0600
From:      wgrim@siue.edu
To:        phk@FreeBSD.ORG
Cc:        kientzle@acm.org, Terry Lambert <tlambert2@mindspring.com>, freebsd-hackers@FreeBSD.ORG
Subject:   Re: Reading rc.conf from C programs? 
Message-ID:  <1041540674.3e14a642d30b5@webmail1.isg.siue.edu>
In-Reply-To: <4351.1041538966@critter.freebsd.dk>
References:  <4351.1041538966@critter.freebsd.dk>

next in thread | previous in thread | raw e-mail | index | archive | help
Well, perhaps I'm missing something here, but can't you just tokenize the items 
in rc.conf using strtok after opening up the file in your C program?

And char buffer sizes is a problem, you can record where the file pointer is, 
do you a strtok on say '=', subtract the new file pointer size with the old 
one, malloc your char string, then move the file pointer back to its previous 
location.

I mean, I may certainly be missing something here, but I've never noticed 
rc.conf be anything other than a left hand value and a right hand value (often 
enclosed in quotes), with both sides being separated by an equal sign.

-Mike




Quoting phk@FreeBSD.ORG:

> In message <3E149EAF.9040100@acm.org>, Tim Kientzle writes:
> >Terry Lambert wrote:
> >
> >> Tim Kientzle wrote:
> >>>I'm trying to figure out how to read and use
> >>>/etc/rc.conf configuration variables from within
> >>>a C program. 
> >> 
> >> 	#!/bin/sh
> >> 	# Throw all of rc.conf into the environemnet so a C program
> >> 	# named "fred" can read any of them with "getenv".
> >> 	. /etc/rc.conf
> >> 	fred
> 
> You can get a decent simulation this way:
> 
> 	#!/bin/sh
> 	echo "*** NOISE"
> 	set
> 	echo "*** DATA+NOISE"
> 	. /etc/rc.conf
> 	set
> 
> Then pipe this into your program and separate the data from the noise.
> 
> -- 
> Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
> phk@FreeBSD.ORG         | TCP/IP since RFC 956
> FreeBSD committer       | BSD since 4.3-tahoe    
> Never attribute to malice what can adequately be explained by incompetence.
> 
> To Unsubscribe: send mail to majordomo@FreeBSD.org
> with "unsubscribe freebsd-hackers" in the body of the message
> 




-------------------------------------------------
SIUE Web Mail

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1041540674.3e14a642d30b5>