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.