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

sean finney seanius at seanius.net
Tue Feb 6 20:50:55 CET 2007

On Mon, 2007-02-05 at 15:07 +0000, Ton Voon wrote:
> On 5 Feb 2007, at 14:49, sean finney wrote:
> > however, over the weekend i started hacking out a bit of code for the
> > ini parsing...  perhaps it was a bit premature to do so given what
> > you've said,  but it does mean the wheel is already half-re-invented.
> > with comments and natural use of whitespace it's currently 178 LoC,  
> > and
> > would probably be less than 2x that to finish it.  the iniparser  
> > LoC is
> > an order of magnitude larger (~2000 just for the src dir), fwiw  :)
> I like to think I give more consideration to people that have  
> something to show - Gavin did some research into the "replacement  
> inline" and said it was hard to do in perl, so that swayed decisions  
> about switching to "defaults from config file".

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 :)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 191 bytes
Desc: This is a digitally signed message part
URL: <https://www.monitoring-plugins.org/archive/devel/attachments/20070206/6d01c74a/attachment.sig>

More information about the Devel mailing list