[Nagiosplug-devel] Gnulib alternative?

Andreas Ericsson ae at op5.se
Fri Aug 22 17:34:00 CEST 2008


Holger Weiss wrote:
> * Andreas Ericsson <ae at op5.se> [2008-08-22 17:09]:
>> ton.voon at altinity.com wrote:
>>> A more entrenched example would be GNU lib - we embed their code (at their
>>> recommendation).
>> While we're at it, I'm pretty much against this too. Plugins, weighing
>> in at an average of 555.57 LoC, that can't be made to run without a
>> rather large compatibility library need to be looked over. Especially
>> when the functions gnulib typically provides are along the lines of
>> strndup(), vasnprintf(), full_write() et al.
> 
> What's your suggestion?  Don't use non-essential stuff like asprintf()?
> Or rewrite everything we need from Gnulib?  Or use something else than
> Gnulib?  If so, what (and why)?  Or just forget about portability?
> 

My suggestion is a combination of the above
Try to work around the asprintf() stuff as much as possible. Since all
plugins run single-threaded and only ever output stuff on stdout, most
of the functionality can be implemented using multiple printf() calls
instead. Everyone has printf().

When you find you repeat the same type of commands lots and lots of
times, implement a wrapper. I'd imagine you'd need wrappers for
malloc(), calloc(), realloc() et al, fe. For preference called
xmalloc(), xcalloc(), xrealloc() etc. The x* calls should all 
die() with an appropriate error message when they fail.

When it's obvious that some functionality from gnulib (or similar)
can remove a hundred or so lines of code from all the plugins combined,
import that particular function into the plugins. If the function
is complex, it's probably too specific. If it's simple, it's most
likely obviously correct (it's not hard to implement strndup() in
a bugfree manner so long as performance is not an issue).

Forgetting about portability is obviously not an option (although I
love coding for a system where I know I have gcc-4.1 and glibc-2.8
available everywhere), but adding a library of 1.7MB to 788KB of
plugin code (not including tests) is just plain weird.

-- 
Andreas Ericsson                   andreas.ericsson at op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231




More information about the Devel mailing list