Remove dependencies in wproc, use wproc_run_callback

Designing the system to keep as few dependencies between the modules
in the system as low as possible is generally a good thing. That
makes each module do it's own thing without knowledge of the other
parts of the system. That means, each functionality has its own
distinct border, and debugging is mostly easier.

One part in this cleanup is wproc:s. wproc handles job types as
integers, and each job type can only be called from one other module.
But the wproc needs to have knowledege of the other module, because
it should be able to call back to that module depending on job type,
by using a switch statement in the wproc result handler.

Better structure is to use function pointers, and design a generic
callback, because then, the wproc module doesn't know anything at all
about the caller, and the explicit dependencies to other modules can
be reamoved.

Using function callbacks makes it having fewer special cases, and
makes it easier to set up test cases for.

Signed-off-by: Max Sikstrom <msikstrom@op5.com>
Fix memory leak when running callback worker job

Destroying a callback job didn't free the callback storage, causing a
memory leak. Fix that!

This wasn't an issue earlier, when callbacks wasn't used much at all
(only some broker modules used that on some user interactions)

Signed-off-by: Max Sikstrom <msikstrom@op5.com>
Notifications: Use wproc_run_callback

By using wproc_run_callback instead of a notify-specific job type, we
can loose the dependency from workers.c to notifications.

Signed-off-by: Max Sikstrom <msikstrom@op5.com>
Convert OCSP and OCHP to wproc_run_callback

Continue to reduce dependencies from wproc to other parts of the system.

Signed-off-by: Max Sikstrom <msikstrom@op5.com>
Convert event handlers to wproc_run_callback

This reduces the knowledege of the surrounding environment in the wproc
module further. That makes it easier to write tests for later.

Signed-off-by: Max Sikstrom <msikstrom@op5.com>
Convert perfdata to wproc_run_callback

performance data doesn't need to handle the result, but convert it to
wproc_run_callback, so that's the only used interface for wproc.

Signed-off-by: Max Sikstrom <msikstrom@op5.com>
Cleanup wproc, when we don't use types anymore

Since the earlier cleanup, all worker calls results in callback jobs,
there's no need to have any job types anymore. Cleanup all type-related
code in wproc, and merge structs, so job contains callback and data
pointers directly

Signed-off-by: Max Sikstrom <msikstrom@op5.com>
naemon/macros.c: removing double check for variable

we already check a few lines before if input_buffer is or not
valid.

as a plus, if a fail during strdup() occurs we return ERROR

Signed-off-by: Ricardo Maraschini <ricardo.maraschini@gmail.com>
naemon/macros.c: using continue to avoid uneede `else'

if we are not `inside a macro' we just copy the current string
to output buffer and keep it going.

Signed-off-by: Ricardo Maraschini <ricardo.maraschini@gmail.com>
naemon/macros.c: avoid to call grab_macro_value_r() if escaped $ found

bringing comparsion of macro with "" a little up. this way we
avoid to call grab_macro_value_r() with a parameter that we
know it is not a macro.

in other words, if strcmp(temp_buffer,"") is false, we know
that macro contains $$ so we just concatenate it to the output
buffer and keep rocking on.

Signed-off-by: Ricardo Maraschini <ricardo.maraschini@gmail.com>
naemon/macros.c: grab_macro_value_r() returns only OK or ERROR

grab_macro_value_r() and it's inner functions only return OK
or ERROR(macro could not be found).

in the last case we just copy the macro as is to the output
buffer as the previous version has being doing since remote
ages.

Signed-off-by: Ricardo Maraschini <ricardo.maraschini@gmail.com>
t-tap/test_macros.c: added tests for escaped $ and invalid macros

added two extra tests to validate if $$ is being escaped to $
and if an invalid macro is copied as is to the output buffer

Signed-off-by: Ricardo Maraschini <ricardo.maraschini@gmail.com>
Remove "extern" from method prototypes

extern is the default behaviour for method prototypes that isn't
declrared as static. Explicitly specify extern in the header files just
adds to the noise for the person reading the header files.

Signed-off-by: Max Sikstrom <msikstrom@op5.com>
Make error messages actually contain the error (wproc timeout)

When rewriting the wproc, a redundant timeout time output was removed.
But appearently to hasty, because the message that it timed out was
also removed. Re-add the message that the command timed out.

Signed-off-by: Max Sikstrom <msikstrom@op5.com>
naemon/macros.c: solved undefined behaviour on incomplete macro

if a macro is defined as `$ something' the previous version of
process_macros_r() returned `$ something$', and that behaviour
is not what we supposedly want.

with the patch below we verify if we reached the end of string
before add a new $ sign, making process_macros_r() leave
string untouched in case of an incomplete macro has been
provided.

also added a test case to assure we are treating this correctly.

Signed-off-by: Ricardo Maraschini <ricardo.maraschini@gmail.com>
tests: Only clean builddir if it's not srcdir

When they're the same, I'm cleaning away my source files. Not nice - not
nice at all.

Signed-off-by: Robin Sonefors <robin.sonefors@op5.com>
tests: Use old-fashioned serial test harness

Because ubuntu seemingly (?) doesn't support the newfangled stuff.

Signed-off-by: Robin Sonefors <robin.sonefors@op5.com>
Merge branch 'ricardomaraschini-macros'
put daemon-systemd in gitignores

Signed-off-by: Sven Nierlein <sven@nierlein.de>
autogen.sh: Accept and pass on command line arguments

We'll want people to be able to build with non-default --prefix
and things like that, so let's help users do just that.

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