ee2f kernel module reading config file, design/code question - The FreeBSD Forums
The FreeBSD Forums  

Go Back   The FreeBSD Forums > Development > FreeBSD Development

FreeBSD Development Kernel development, writing drivers, coding, and questions regarding FreeBSD internals.

Reply
 
Thread Tools Display Modes
  #1  
Old April 19th, 2010, 01:18
eyebone eyebone is offline
Member
 
Join Date: Dec 2009
Posts: 148
Thanks: 22
Thanked 5 Times in 2 Posts
Lightbulb kernel module reading config file, design/code question

hi folks,

i coded a simple module, which shall read a configuration file residing in userland. now, here i am stuck first in a design question and secondly on "how to implement such".

the module is intended to handle certain requests onto a permission configuration file, which i don't want and can put hardcoded into the code(the module shall on a configuration change not recompiled the whole time )

first, and most, i wonder what would be the common/suggested way for a kernel module to get some kind of configuration(is this even intended?).
is it usual read it at runtime(after loaded, after refresh), is it more suggested to have a userland daemon which is communicating with the module or a possible device driver?

now, secondly, in regard to the design question what would be the proper functions to do such in kernelland? i know a bit about the uio stuff for device drivers and copyin/copyout as well.

regards,
Reply With Quote
  #2  
Old April 19th, 2010, 03:03
crsd crsd is offline
Member
 
Join Date: Nov 2008
Location: Russia, Krasnodar
Posts: 420
Thanks: 8
Thanked 92 Times in 82 Posts
Default

You can set initial configuration via device.hints(9). And there are a lot of kernel modules reading sysctl's.
Reply With Quote
  #3  
Old April 19th, 2010, 08:14
trasz@ trasz@ is offline
FreeBSD Developer
 
Join Date: Feb 2008
Location: Warszawa, Poland
Posts: 178
Thanks: 7
Thanked 37 Times in 29 Posts
Default

It depends on e.g. how large and complicated the config file would be. I'd start with sysctl. Then you could just put the configuration variables into /etc/sysctl.conf; there is an rc script to set these values at system startup. If you want to be able to set configuration first and load the module later, you could implement them as tunables (see kenv(1)). There is an API for easily accessing both in the kernel.
Reply With Quote
  #4  
Old April 19th, 2010, 16:46
phoenix's Avatar
phoenix phoenix is offline
Moderator
 
Join Date: Nov 2008
Location: Kamloops, BC, Canada
Posts: 3,178
Thanks: 43
Thanked 715 Times in 587 Posts
Default

Quote:
Originally Posted by crsd View Post
You can set initial configuration via device.hints(9). And there are a lot of kernel modules reading sysctl's.
Using /boot/loader.conf is a better solution. device.hints gets overwritten by mergemaster, while /boot/loader.conf doesn't get touched. Plus, it keeps everything nicely in one file.

Anything that can go in device.hints can also go into loader.conf.
__________________
Freddie

Help for FreeBSD: Handbook, FAQ, man pages, mailing lists.
Reply With Quote
  #5  
Old April 21st, 2010, 20:14
eyebone eyebone is offline
Member
 
Join Date: Dec 2009
Posts: 148
Thanks: 22
Thanked 5 Times in 2 Posts
Default

hej guys,

first thank you for your input. wasn't a bit out of time. i decided to give it a first shot with sysctl and see how things are going and if the config gets not to complex.
i'll be back with module or thread here in some days i guess

till then, best regards
Reply With Quote
  #6  
Old April 29th, 2010, 19:23
eyebone eyebone is offline
Member
 
Join Date: Dec 2009
Posts: 148
Thanks: 22
Thanked 5 Times in 2 Posts
Default

ok, i implemented some basic's but i am somehow stuck on the sysctl issues. i added a new branch with SYSCTL_ADD_NODE, i can add there strings and it is, working almost fine.
now i am looking for adding additional node to the already created node, to achieve this tree:

Code:
application.node1
application.node1.family1
application.node1.family1.id=0
application.node1.family1.name=username
application.node1.family2
application.node1.family2.id=1
application.node1.family1.name=anothername
i tried to accomplish this through:

Code:
test2 = SYSCTL_ADD_NODE( NULL, SYSCTL_STATIC_CHILDREN(test1),OID_AUTO, "family", CTLFLAG_RW, 0, "test2");
and resulted into a compiler error message:

Code:
tester.c:314: error: 'sysctl_test1_children' undeclared (first use in this function)
i guess i made a basic mistake for SYSCTL declaration(do i need to use SYSCTL_DECL for instance?) or somekind of handler function(how would this look like?)

i wonder as well how i can implement a good way of searching through the sysctl values on module side to decide what actions to take. is there some kind like LIST_FOREACH mechanism?

additionally i figured after creating a node and not adding a string or integer results on my side with a kernel trap during kldload, is there a specifig reason for this?

someone can point me to a paper/book/self explaining module code for SYSCTL topic?

best regards,

Last edited by eyebone; April 29th, 2010 at 21:36.
Reply With Quote
  #7  
Old April 29th, 2010, 21:45
eyebone eyebone is offline
Member
 
Join Date: Dec 2009
Posts: 148
Thanks: 22
Thanked 5 Times in 2 Posts
Default

ok, i found a perfect example:

http://fxr.googlebit.com/source/shar...NETBSD-CURRENT

it is from netbsd and serves to understand the basics of the usage
Reply With Quote
Reply

Thread Tools
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to add source file infomation to kgdb for my kernel module snaily FreeBSD Development 9 February 7th, 2010 09:39
Building kernel modules without kernel source code holycow General 5 April 2nd, 2009 09:18
Reading currently running kernel configuration pbd General 9 March 5th, 2009 03:53
Is the cciss kernel module available in the installation kernel & other general Q's osx-addict Installing & Upgrading 2 March 2nd, 2009 18:14
Config File and WTMP bamcis General 3 February 28th, 2009 22:09


All times are GMT +1. The time now is 16:10.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
The mark FreeBSD is a registered trademark of The FreeBSD Foundation and is used by The FreeBSD Project with the permission of The FreeBSD Foundation.
Web protection and acceleration provided by CloudFlare
0