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)
Move some fileno() calls outside locked intervals.

They don't need to be inside.

(cherry picked from commit b363ec92b36effcdff70b865b57c01d324fbb7b8)
Close FILE* also on premature returns from cf_pclose().

At the same time, simplify the locking and make sure we don't call
cf_pwait(-1), which made no sense.  The check that CHILDREN is
non-NULL could have been invalidated, between unlock and lock, by
another thread's attempt to realloc() it failing, so the locking
change could avoid a crash.

(cherry picked from commit ae5b3559dfc6c1f9d2c869734a6dfaaa45358110)
Leak-fix: free(CHILDREN) when done with array.

If it makes sense for CloseChildrenFD() to close all the child FDs,
surely it also makes sense to clear the array.  The previous commit's
changes to locking in cf_pclose() make this safe.

(cherry picked from commit 83f6bb66d44ffde9d95644212476fcff7bb14318)
Rename a variable for clarity.

SetChildFD's "new_fd" was just a new size for a buffer (indexed by
fd), not actually a "real" fd in any sense.

Add a TODO about why high fd values are reported as error (but handled
gracefully, so they're no real problem).  Not clear from the context.

(cherry picked from commit aa5c81170a70d39359e1acd7e0a6ce5860c28e6c)
Leak-fix: clean up lexer state after parsing.

Also make the provenance of yacc/lex globals explicit.

(cherry picked from commit 921e1d8b5f42137c5f80643e4e11f2921e0e3c22)
Document a known leak.

(cherry picked from commit 52bd57bf49af7b058fffc4e0b692e3fff7cdb215)
Fixes for inappropriate formats in a test.

unsigned long isn't size_t.

It made no sense to use an intptr_t for the counter of a loop bounded
by an int.  The counter is cast to void*, but casting it via intptr_t
(to silence warnings about size-mangling casts) makes more sense than
making the counter actually be an intptr_t.  Likewise, when collecting
the int back from a void*, cast via intptr_t but use an int.

(cherry picked from commit ffadbb0722c5c0da71e86efd147ceb61af67e7fb)
Revert "Leak-fix: clean up lexer state after parsing."

This reverts commit 921e1d8b5f42137c5f80643e4e11f2921e0e3c22.

(cherry picked from commit 4d045243961ab16376fa49fd1838a067085e0148)
Add test for failed_returncodes

When kept_returncodes or repaired_returncodes are specified
failed_returncode is not defaulted properly.

(cherry picked from commit 196fa94ae1cf10d3383b11af9e7f4c3405bc8120)
Redmine#5986: fix to assume all non-specified return codes are failed

(cherry picked from commit 4e58ff2575b51a42829c469a1d4367aabe99a012)
Redmine#5981: clarify --gainroot=env

(cherry picked from commit 6c2f125cb6bd5249c415a33ea98f81f3496b50c0)