lib/iocache: Fix iocache_resize()

Not using the new buffer and not updating the bufsize was pretty
damn stupid, to tell the truth. In all honesty, we should probably
return some iocache specific error in case someone's trying to shrink
the buffer to less than iocache_available(ioc), in order to prevent
data losses.

OTOH, that's really up to the caller.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2004 5f96b256-904b-4d8d-8c98-d829582c6739
lib/iocache: Make struct iocache an opaque type

With two simple helpers added (and some redundant code removed), this
means we're free to modify the iocache structure any way we want and
we'll never break its ABI.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2005 5f96b256-904b-4d8d-8c98-d829582c6739
lib/kvvec:buf2kvvec() Fix key/value pair counting (again)

The last patch assumed we would send the delimiter to the buf2kvvec()
machinery, and that the delimiter was the same as the pair separator.

Since that's an obvious bogosity in a standalone library, we fix that
here and will instead make certain we only send the buffer we want
buf2kvvec() to operate on.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2006 5f96b256-904b-4d8d-8c98-d829582c6739
lib/kvvec.h: Remove typedefs for structs kvvec and kvvec_buf

They add no value for non-opaque types and aren't used internally,
so we get rid of them so people know what type they're using.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2007 5f96b256-904b-4d8d-8c98-d829582c6739
libnagios headers: Fix doxygen commenting

It's nifty and we'll want to use it, but for preference without
the retarded amount of warnings the previous state of the comments
caused doxygen to spit out.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2008 5f96b256-904b-4d8d-8c98-d829582c6739
libnagios: Add runcmd and worker libraries

Although the worker library isn't, strictly speaking, a library as
much as it is a toolkit and some application logic, it's nifty to
have for creating remote workers or as an example on how to use the
other parts of libnagios.

The runcmd library is inherited from the plugins project and might
need to be refactored for performance later.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2009 5f96b256-904b-4d8d-8c98-d829582c6739
Add the wproc program

This small program demonstrates the basics of how workers work
and is quite useful when testing the worker process parts of the
nagios library.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2010 5f96b256-904b-4d8d-8c98-d829582c6739
core: Fix memory leak in log_service_event()

This was introduced by 9059a683 (svn revision 1952 at the moment).

Patched-by: Michael Friedrich <michael.friedrich@univie.ac.at>
Signed-off-by: Andreas Ericsson <ae@op5.se>

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2011 5f96b256-904b-4d8d-8c98-d829582c6739
lib/squeue: Remove branch prediction hackery

It doesn't change the generated assembly code one bit, so we might
as well get rid of it.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2012 5f96b256-904b-4d8d-8c98-d829582c6739
core: Remove dead prototype for resort_event_list()

It was removed when we switched to using the squeue library instead
of linked lists for scheduling, but the prototype lingered on.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2013 5f96b256-904b-4d8d-8c98-d829582c6739
core: Zero-initialize low-priority timed events

Without doing this, we might get random usec values in the
sq_event, which is quite bad since we're using it to determine
runtime in the scheduling queue, which in turns decides the
amount of time we spend polling.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2014 5f96b256-904b-4d8d-8c98-d829582c6739
lib/squeue: Remove debugging output

Noone will see it when we're running, and we still return proper
error messages to the callers, so we needn't bother overly.

We do add an assert() to make check we don't get usecs larger
than 1000000 though.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2015 5f96b256-904b-4d8d-8c98-d829582c6739
lib/worker: Remove incessant logging from workers

While we're at it, we also kick out a debug printf().

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2016 5f96b256-904b-4d8d-8c98-d829582c6739
lib/worker: Close parent's end of socketpair before initialization

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2017 5f96b256-904b-4d8d-8c98-d829582c6739
core: Add worker management helpers

This provides the in-core helpers needed for us to paw over all
external commands to the worker processes with a minimum of code
duplication.

While at it, we add the struct rusage to the check result struct,
so we can keep track of what resources plugins consume.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2018 5f96b256-904b-4d8d-8c98-d829582c6739
core: Handle brokered I/O events adding high priority events

Previously we used to go ahead with the event we got from the
queue no matter if events brokered from the I/O broker turned
were added that were supposed to be run before that one. We still
do (sort of), except that now we prioritize the earlier scheduled
events if the first event is scheduled far enough into the future.

"Far enough" means "one second" in this case.

While we're at it, we remove the fairly useless wproc_poll() call.
Since nagios_iobs is a global variable and wproc_poll() is just a
wrapper around iobroker_poll() called with nagios_iobs and the
timeout as variables, we really don't need the wrapper.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2019 5f96b256-904b-4d8d-8c98-d829582c6739
core: Run host and service checks through a worker

Fascinating observation; With a large process (+100MB) we can achieve
1121 fork()'s per second. With a small process as parent, we can
achieve 13891 fork()'s per second, best of five runs on my laptop.

Even accounting for the message passing, which has a constant overhead
of about 50 nanoseconds (two memcpy() and some function call overhead),
this is a clearly superior solution, even if we don't account for the
fact that we're now capable of utilizing parallelization as well, so
we can multiply the number of fork()'s with the number of online cpu's
minus 1 instead of having it fixed at 1.

Naturally, performance will decline when the fork()'ed programs do
something sensible instead of just exiting, but since the same program
was used to measure fork() performance with large and small processes
we can still expect a huge improvement.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2020 5f96b256-904b-4d8d-8c98-d829582c6739
core: Run eventhandlers, OC[SH]P commands and others through workers

They used to be run serially. This parallelizes them, as well as
offloading them to a smaller process, which means a huge performance
benefit.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2021 5f96b256-904b-4d8d-8c98-d829582c6739
Merging with trunk.
core: Broker the end of a timed event as well as the beginning