LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-20-2009, 02:50 PM   #1
rever111
LQ Newbie
 
Registered: Mar 2009
Posts: 5

Rep: Reputation: 0
Retrieving entries from rc.conf on FreeBSD


Hey.

I was wondering how can i retrieve variables from rc.conf from a C program? I don't wanna read in the file and do a search for the variables name then strip the quotes etc... I was wondering if there is a standard way of doing this at runtime?

Sorry if this is a dumb question, i did most of my programming on windows, so i am a little rusty on the FreeBSD architecture.

Regards.
 
Old 03-20-2009, 03:14 PM   #2
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 676

Rep: Reputation: 136Reputation: 136
Quote:
Originally Posted by rever111 View Post
Hey.

I was wondering how can i retrieve variables from rc.conf from a C program? I don't wanna read in the file and do a search for the variables name then strip the quotes etc... I was wondering if there is a standard way of doing this at runtime?

Sorry if this is a dumb question, i did most of my programming on windows, so i am a little rusty on the FreeBSD architecture.

Regards.
I suggest writing script that will source rc.conf and write whatever you like to stdout.
Then your c program can invoke this script via popen and get all information it's needed.

Or you can invoke it as

Code:
script | c_program
then your program should read data from the standard input
 
Old 03-20-2009, 03:19 PM   #3
rever111
LQ Newbie
 
Registered: Mar 2009
Posts: 5

Original Poster
Rep: Reputation: 0
well, thats pretty much on a level of writing it in c code. Are there maybe system calls that parse rc.conf or something? Or do all the application that use it, do something like a script that you meantioned b4?
 
Old 03-20-2009, 08:25 PM   #4
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by rever111 View Post
Hey.
I was wondering how can i retrieve variables from rc.conf from a C program?
A C program that you will write?? Or just using a program coded and compiled in C? if its the latter then, use awk.
Code:
awk -F"=" '/gateway/{print $2}' /etc/rc.conf
 
Old 03-21-2009, 12:01 AM   #5
rever111
LQ Newbie
 
Registered: Mar 2009
Posts: 5

Original Poster
Rep: Reputation: 0
A C program that i will right. I am righting it right now, so i am looking for a best way to retrieve stuff from rc.conf (fastest). A script is good, but i can do it faster with raw file acces. I was just wondering if there are any system function for doing that, or something like that.
 
Old 03-21-2009, 12:06 AM   #6
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by rever111 View Post
A C program that i will right. I am righting it right now, so i am looking for a best way to retrieve stuff from rc.conf (fastest). A script is good, but i can do it faster with raw file acces. I was just wondering if there are any system function for doing that, or something like that.
the term "faster" has different meaning. Unless you are doing a school assignment where you have to use C, using tools such as awk (which is basically just C program already compiled) is much "faster" than having to code it by hand. It is called faster development time.

Last edited by ghostdog74; 03-21-2009 at 12:11 AM.
 
Old 03-21-2009, 10:52 AM   #7
rever111
LQ Newbie
 
Registered: Mar 2009
Posts: 5

Original Poster
Rep: Reputation: 0
True, but there are inherent cost associated with calling third party software, including not always knowing whether it is on the system. As for faster development time, the 20 minutes that it is gonna take me to write the C code, vs the 2 minutes if i use a predefined program then yeah....i do save the 18 minutes. A/w I was wondering if there are system level function to retrieve the stuff from rc.conf, or if rc.conf is somehow accesible from an application with accessing it as a file (one again sorry if this is retarded, i've mostly programmed in windows, so i am used to concepts of registries and stuff like that for system setting, which contains their own APIs to access them).
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Detected IP entries in resolve.conf Luna-tic Linux - Networking 3 07-13-2008 06:14 PM
New entries to /etc/modeprobe.conf kromberg Fedora 1 04-20-2008 09:37 AM
multiple DNS entries to /etc/resolv.conf noir911 Linux - Networking 1 02-26-2007 11:43 PM
entries in the /etc/resolv.conf ! prabhatsoni Linux - Networking 4 01-28-2006 04:52 AM
too many entries in lilo.conf oski Mandriva 4 09-01-2003 12:47 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:16 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration