[Nagiosplug-devel] RFC: Plugins config file (final proposal)

Ton Voon ton.voon at altinity.com
Wed Feb 7 15:47:57 CET 2007


On 6 Feb 2007, at 19:50, sean finney wrote:

> okay, i've put the finishing touches on it and committed it  
> (parse_ini.c
> and parse_ini.h).  there's also a small main function in  
> parse_ini.c to
> show how the function works in case it's not obvious.  the only  
> publicly
> exported function is:
>
> char* np_get_defaults(const char *locator, const char  
> *default_section);
>
> where locator is in the form [stanza[@[inifile]]].  if i mis- 
> remembered
> that it's [[[stanza]@]inifile] it shouldn't be too hard to flipflop  
> the
> logic.  the string returned is either a NULL pointer or a dynamically
> allocated string in the form "--foo=bar --foo2=bar2....".
>
> i haven't incorporated it into the build system or anything at this
> point (having a library with main() in it wouldn't work so well  
> anyway),
> so if you want to give it a go prep the build area as normal and then
> the following ought to compile it into a.out:
>
> gcc -Wall -g parse_ini.c   -I../plugins -I.. -I../gl utils_base.o
>
> there are still the fine details like syntax/quoting/etc, but the
> hard work is done.  both files with comments/whitespace and the
> unnecessary main function included are 266 LoC total, most of which is
> dedicated to allocation and parsing.  don't you just love c?  :)
>
> i'd appreciate those with the time and the C-fu to take a look at the
> code, double checking for off-by-one and similar type stuff.   
> questions,
> comments, etc are also encouraged :)

Good work, Sean!

I've added some extra files in CVS, with two test ini files - one of  
which is based on Config::Tiny's test file. I don't think they should  
conflict with the existing build.

You're right about not having these files in the build system, so  
I've added a Makefile.config-opts into lib/ and lib/tests/. A make -f  
Makefile.config-opts in lib/ will create the library object file.

If you install libtap (there are some instructions on http:// 
tinderbox.altinity.org) and go into lib/tests/ and run make, it will  
create a ./test_ini executable. Run this to run some tests. At the  
moment, there are failures re: whitespace at the end of lines. There  
are some extra tests as well commented out in test_ini.c, but these  
are segfaulting for me.

A few comments:

   - I've removed the main() section in parse_ini.c since we can test  
in test_ini.c now
   - the section name cannot contain "@". I think this is fair  
enough, so will add into RFC
   - Config::Tiny removes leading and trailing whitespace in the  
stanza name for legibility reasons - good idea? I've got some tests  
for those, but they are  segfaulting
   - Config::Tiny allows parameter/values before any stanzas. We have  
reserved the stanza name "default" in the RFC - is it better to just  
have that first part as reserved?
   - your routine allows comments after a parameter/value, but  
Config::Tiny doesn't. Should we recommend not using this or patch  
Config::Tiny?

I'll merge the RFC into the dev guidelines since I think we're all in  
agreement to do this.

Ton

http://www.altinity.com
T: +44 (0)870 787 9243
F: +44 (0)845 280 1725
Skype: tonvoon






More information about the Devel mailing list