Paving the way for worker-processes

This introduces 'libworker', which is a maturing library to
handle multiple worker processes that help execute commands
and gather the output, exit status and various resource
usage metrics from those commands.

Naturally, it will be extremely helpful in reducing Nagios'
currently pretty high I/O usage, but should also provide
eventbroker modules with a neat way of interacting with
other programs without having to handle all the tedious
socket polling code themselves, but instead focusing on
application logic.

This is still incomplete and won't even get built into
Nagios when compiling yet though, so Nagios still works
exactly the same as it always has.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Revamp libnagios somewhat

cmd2strv is moved into the runcmd api, which doesn't really work
without it and is its only caller.

The other api's get minor overhauls as well.

Signed-off-by: Andreas Ericsson <ae@op5.se>
gitignore *.a files

For libnagios.a, since we don't want to commit it, ever.

Signed-off-by: Andreas Ericsson <ae@op5.se>
lib/kvvec.h: Typedef struct kvvec* to kvvec

As per libnagios standards, more or less.

Signed-off-by: Andreas Ericsson <ae@op5.se>
lib/Makefile.in: Add distclean target

Signed-off-by: Andreas Ericsson <ae@op5.se>
Makefile.in: Take the lib/ dir into account

Signed-off-by: Andreas Ericsson <ae@op5.se>
base/Makefile.in: Make sure libnagios builds before linking

If one builds from the base/ directory, it won't get built without
this patch.

Signed-off-by: Andreas Ericsson <ae@op5.se>
configure.in: Add support for lib/Makefile.in

Signed-off-by: Andreas Ericsson <ae@op5.se>
Re-generate the ./configure script

Why it's checked in to version control I'll never know, but since
it's there, we should keep it up-to-date.

Signed-off-by: Andreas Ericsson <ae@op5.se>
iocache: Augment api with some nifty and necessary functions

In particular, we want the iocache_use_delimiter() function for
our purposes here, which save us from duplicating a lot of code
for no good reason.

Signed-off-by: Andreas Ericsson <ae@op5.se>
kvvec: Remove debugging from buf2kvvec()

Signed-off-by: Andreas Ericsson <ae@op5.se>
worker.h: remove superfluous macros

Signed-off-by: Andreas Ericsson <ae@op5.se>
worker: Use a separate iocache for each worker

It makes sense for the worker master.

Signed-off-by: Andreas Ericsson <ae@op5.se>
worker: Remove dependency for asprintf() and vasprintf()

We can easily replace it with a small static buffer and a single
vsnprintf() call instead, which is included in C99 at least.

Signed-off-by: Andreas Ericsson <ae@op5.se>
worker: Make send_kvvec() available outside worker.c

It's quite nifty to use for callers as well, so we'll do just that.

Signed-off-by: Andreas Ericsson <ae@op5.se>
send_kvvec(): Write the passed kvvec to the passed socket

Writing it to the master socket makes absolutely no sense, since we're
then ignoring one argument. The caller should know where it wants to
put the data anyway.

Signed-off-by: Andreas Ericsson <ae@op5.se>
worker: Replace iocache2kvvec() with iocache_use_delim()

... and a small loop that does the remaining parts of what
iocache2kvvec() used to do for us.

Signed-off-by: Andreas Ericsson <ae@op5.se>
send_kvvec(): Use nul byte as separator between keys and values

This makes send_kvvec() safely usable for testresults containing
newlines and equal signs again and is the way it should have been
from the start.

Signed-off-by: Andreas Ericsson <ae@op5.se>
worker.c: Let callers specify an initialization function for workers

Since we'll be using them as lightweight programs, we need to be able
to free() memory, but this way the library doesn't require being
linked to the main Nagios code in order to call functions inside it,
which is obviously a good thing as that means we can also use it to
write and NRPE replacement or some such.

Signed-off-by: Andreas Ericsson <ae@op5.se>
wproc: Use the now-global send_kvvec() instead of handhacking it

Signed-off-by: Andreas Ericsson <ae@op5.se>