Advance ap if socket(2) fails

In the case where socket(2) fails in SocketConnect, ap will advance,
causing an infinite loop.

https://dev.cfengine.com/issues/6560
Merge pull request #1952 from worr/bug/socketconnect-loop

Advance ap if socket(2) fails
Don't pass literal strings when a char* is needed.

Perhaps IsUserNameValid() shouldn't need to modify its parameter; but
its test shouldn't pass it a const char* parameter as long as it
claims it does.  Turn the literals into initializers for non-const
arrays.
Purge dangling hspace
Split a long line, ditch some superfluous assignments.

Assigning a variable the value it already has is just distracting.

When a condition combines three flags with || and the flags are very
similar, it's much easier to see what they share and where they differ
if they're lined up vertically, with the identical parts equally
indented.
Simplify GetAcpi().

Make various variables more local.
Make a conditional more readable.

Eliminate a buffer and the sprintf into it where all we needed was to
search for one digit in a string; adding the (singled-digit) int to
'0' will get the digit, with strchr replacing strstr to find it.
Replace a repetitive switch where indexing into a simple array can do
the same job more straightforwardly.

Discovered that a Log() was trying to output the contents of a path
buffer that hadn't actually been initialized; it should have contained
the name of the directory we'd just failed to open, so initialized it
that way.
Make variables more local in PurgeOldConnections().
Simplify DetermineCfenginePort().

Make a variable more local, turn an else { if ... } into an else if.
Only Log() that we've set the port if we actually did set it.
Fix a badly-thought-out loop.

The BSD compiler warned that i >= 0 is always true for a size_t i; the
loop conditioned on that could have spun for ever.  So turn it into a
while that terminates correctly and simplify what's left.
Replace hard-coded number with symbolic expression.

Where PurgeOldConnections() checked the age of a connection, it simply
compared the difference to 7200.  Writing that as 2 * SECONDS_PER_HOUR
makes it clearer what it actually means.
Fixing LocalExec in cf-execd-runner.c

The premature return was only doing most of the tidy-up needed, so
make it a break instead and add a flag for whether the command
actually completed; use that to condition the one Log() after the loop
that wasn't appropriate to run after this failure.  The alternate
branch to that return's if was in fact the only path out of the loop
for which the Log() was relevant, so made it set the flag for that
Log().  Made the Log() say something sensible as an alternative when
the work isn't complete.  Simplified the code to detect a non-blank
string.

Code skipping spaces at the start of a string could be simplified to
avoid the need for a bool flag to say whether we found anything else.
Break out of thread main-loop on signal.

If we get a signal that we catch and use as reason to exit, we need
our threads to exit, not just the main thread.  I believe it's safe
for the threads to simply call IsPendingTermination(); it's not
super-critical that they synchronise round that, as long as they
notice after a few laps round their loops.
Typo-fixes and a rephrase in HACKING.md

s/absued/abused/
s/indenpendent/independent/
Rewrote garbled line about keeping log messages atomic.
Cleanup in FileReadFromFd().

It was possible to return without having set *truncated.
Closing the file was repeated in several places.
Our coding standard demands braces on a conditional's body, even when
it consists of just one statement.  So add those braces.

Restructuring the loop body's conditionals as an if/else-if/else
chain got rid of some continue;s.
Moved a couple of assignments out of conditionals.

Easier to read this way.
warning-fix: Correct signature of SaveXmlCallback().

It's used as a SaveCallbackFn, so needs to accept a NewLineMode as
third parameter, even if it does ignore it.  It should also be a
static function (nothing outside its file uses it); and we may as well
simplify the #if-ery around it and its one caller.
Propagate IntFromString's long-ness through PromiseGetConstraintAsInt.

It makes no sense to truncate an int once we've successfully read it.
Assorted clean-up and simplification in policy.c
Simplification and clarification in SearchAndReplace().

Simplify the loop logic from a for (;;) with a conditional return at
the start of its body to a suitable while (albeit with assignment in
its condition), so that we can have return at the end of the body.
Declare variables after the early returns that don't use them.
Only compute length of search string once.
Rename variables.  Simplify arithmetic.
Clean-up in LinuxDebianSanitizeIssue()

Make its @brief actually brief.  Describe what it does more
accurately.  Its caller ignored its return which was always success;
so don't bother with it, just be void.  The implementation was messy;
tidied it up and simplified it.