Merge pull request #1770 from kacfengine/3.6.x

3.6.x Cherry picks
Fix CFLAGS order.

(cherry picked from commit 6cbd061d92c1dc13357d0cb87b668de9cae80798)
Fix detected flags from ACX_PTHREAD being reset.

(cherry picked from commit a131311e4f19c807a58561c37cdac99be5418fe8)
Include path should be CPPFLAGS, not CFLAGS.

(cherry picked from commit 19a5d6ac640e1e75e262cc1e575a8b3470bacf7b)
Revert "Retrying SSL_accept and SSL_connect if error.", again.

This reverts commit 39375e1bb04f165d8fe996734fe17eaccc78ca81.

All our code uses *blocking* sockets. We shouldn't have to deal with
fragile polling loops and secondary time-outs with no real reason.

There *is* one case that we get the SSL_ERROR_WANT_READ error even
though our socket is blocking, but I'll comment and cover that one case
with a separate pull request.

Conflicts:
	cf-serverd/tls_server.c
	libcfnet/tls_client.c

(cherry picked from commit 098b7a4787fe24b5b92ca4d42bc502ba2b1e617b)
Make sure there are no lingering threads when we clean up.

(cherry picked from commit 7ec31723d053f3affb5e2356245dbe707c701dbf)

Conflicts:
	cf-serverd/cf-serverd-functions.c
Merge pull request #1771 from jimis/3.6.x

Cherry-picks from master to 3.6.x.
Pass GenericAgentConfig to NoteVar/Class plugin calls

(cherry picked from commit 6dbe12ff833e14186ecae6d5c7b1149005d823e2)
Add (partial) finalization for generic agent.

We have an initialization function for the generic agent, that calls
initialization code for cfnet; but neither had matching finalize code,
even though the cfnet one calls initializations that do have matching
shutdown code (that no-one calls).  Similar problems with server.

Begin sketching what relevant clean-up would look like, based on the
first few leaks I saw due to its absence ...

Fold EvalContextDestroy() and GenericAgentConfigDestroy() into
GenericAgentFinalize(), to simplify everywhere's final clean up.  In
the process, catch a few cases that used to neglect the former.

(cherry picked from commit ec9c10953192e2627a757ec92fb1a8b2e2a378b7)

Conflicts:
	cf-serverd/cf-serverd-functions.c
	cf-serverd/cf-serverd.c
Clear auth and ACL data on exit, when possible.

Moved clean-up code for SV, *_acl and friends to a separate function
(shortening CheckFileChanges) and arranged for StartServer() to call
this, when it safely can, on exit to (try to) avoid some boring leaks
that clutter valgrind's logs.

(cherry picked from commit bbfdf6c11b7311afa0a2550bcc319c9b53348e10)

Conflicts:
	cf-serverd/cf-serverd-functions.c
Leak-fix: clear away PRIVKEY and PUBKEY in TLSDeInitialize().

(cherry picked from commit d758fd4d9ec8a79dc757d5ed6a5a6b5a46f3847c)
Merge pull request #1773 from jimis/3.6.x

Cherry pick network-related Eddy's commits from master to 3.6.x.
Redmine#6189: Store the hardcoded bootstrap file in a variable

..instead of using it directly to prevent old GCCs from failing due to
fprintf usage as a macro

Modified by: Kristian Amlie <kristian.amlie@cfengine.com>
(cherry picked from commit f0ebf2388f4c135b3a07075a8418cd040d80da65)
Do not replace stdout in child worker process.

Unidentified spurious problems on Solaris 9, with file descriptor 0
*not* corresponding to stdin, triggered me to change the worker child to
not close its stdout and replace it with the dup()ed pipe
descriptor. Instead, it now fprintf()s directly to that pipe.

Didn't fix the problem on Solaris (still investigating) but still its a
good change.
(cherry picked from commit 3cc6d976795a200d92b36beca842de39ff28bde7)
pthread_cond_timedwait() takes absolute time

Also fix threads actually delivering the signal when they should.
This fixes test failure on Solaris.
(cherry picked from commit b3ba854eafbb5ee052f9a31538ca24d323b1a669)
Using high precision clock should avoid corner case...

where time(NULL) returns e.g. 5, but time is 5.99.
Thanks to @kacfengine for spotting this.
(cherry picked from commit f5fe3ee07e8e1b71a8df4f8c388bb5159160a153)
Redmine #5452: add acceptance test for maparray()

(cherry picked from commit ea833b18e2de873d64a26c5e7b0d26e9e7a60e3e)
tests/acceptance/01_vars/02_functions/staging/maparray.cf: minor changes, still in staging

(cherry picked from commit eed31885a98ac1c63c2b7b3b0fd53ae98121d861)
Redmine#5882: add INFORM message when the given permissions will be filtered

(cherry picked from commit e857b30a52f2e566cc9fa8340601144f94c060ec)
Leak-fix: free db_handles[*].filename in CloseAllDBExit().

The filename was created by xstrdup() via DBIdToPath() and
MapNameCopy(), so we have a duty to free() it eventually.

Cowardice: I'm only doing it, for now, if all DB users finished, since
I don't know what pain it might cause for one of them that's still
running ... but I left a TODO comment to look into that.

(cherry picked from commit 5460cff2377db1b511e4701775e9871e7217fe00)