Wrap HACKING.md where lines exceed 78 columns.
HACKING.md: add do-while exception, and rewrap some text around it.
Add: Acceptance test for ifelapsed

Ifelapsed should always be respected, especially at the individual
promise level.

Ref: https://dev.cfengine.com/issues/6334
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.
Kill some stray apostrophes.

Some function names were formatted using '%s'' with two dangling
apostrophes; there should only be one before and one after !
Also: split a long line, purged dangling hspace, added braces demanded
by coding style.
Leak-fixes and clean-up in FnCallPackagesMatching().

Move computation of regex outside the loop - no need to recompute the
same regex for every line of the CSV file ! - and pre-compile it so
that we can search using it more efficiently.  Localise all the
variables related to that at the same time.

Split up various long lines, notably when Log()ging failure to open
the inventory.

Move creation of some objects to where they're needed, to save the
need to tidy them away on failure in the interval.

Don't leak the allocated line when it doesn't match our expectations.

Restructure the for(;;) loop as a while with assignment in its
condition so as to move the failure-handling out of the loop and avoid
duplication of clean-up code.  Reviewed the error message on that
failure: it claimed fread() was involved, which is a lie, so re-worked
it.
Petty leak-fix: close socket on which we failed to listen.

About to exit with error anyway, so not crucial.
Tidy up in SocketConnect().

PR #1952 added an ap = ap->ai_next in an if branch that duplicated one
in its else; replacing these with one after the whole branch put the
loop in the form of a for() unrolled as a while, so I rolled it up as
a for().

If an iteration of the loop managed to create a socket but failed to
connect it, we were leaking it (unless it happened to be the last time
round the loop); the "on failure close the socket" was after the loop,
where it belonged inside.  Further, the Log()ging of that tried to use
GetErrorStr() when enough other functions had been called since the
error that the error string might easily be from something unrelated
to the connection failure.  So Log() before closing the socket in the
loop and don't try to include an error string with the final "none of
it worked" Log().

Tweaked a couple of other Log() messages.
Don't leak return from logging hook function.
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.
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.
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.
Fix misguided strlen() in Chop() and StripTrailingNewline().

They check strlen() doesn't exceed max_length, which callers typically
pass as the buffer size; either this test is a waste of time or, when
it might fail, it'll involve reading past the end of the buffer to
discover the error - which is bad.  So use strnlen() instead, this is
what it's for.  Don't bother special-casing empty string; and re-use
the value strnlen has returned to us instead of calling again at the
start of the search for the last non-space.  Only '\0' out the first
trailing space, rather than filling the tail with '\0' over each
space.  (For "space" read isspace() in Chop() and '\n' in
StripTrailingNewline().)  Structure the two functions the same way.
Cast is...() character class parameters to unsigned char.

These functions (isprint, isspace, etc.) take an int with "the value
of an unsigned char or EOF" according to spec.  Passing a char is thus
suspect, since char can be signed or unsigned, depending on platform.
(Many previously cast to int, which was pointless.)
redmine6147: the other fix.

It's possible for the handling of a connection to close that
connection; it's typically better to leave the HandleConnection()
level of code to deal with that, but this level may as well at least
cope gracefully if something *has* done so - provided it's suitably
marked the connection as having been closed.  So have DeleteConn()
actually pay attention to whether the socket is valid before closing
it.
Rework KeepServerRolePromise().

I noticed a spurious continue (it was a no-op), so looked closely.
The inner loop tested a condition that didn't depend on any inner loop
variable, so I moved that outside the loop.  Different branches of the
switch on rval's type tested lval against various things; it makes
more sense to test the lval first and use that to decide what the
rval's type should be.  In particular, even if an "authorize" has a
value of the wrong type, we should report it even if it's currently
not active due to depending on a class that's not defined.  Moved a
function call outside a loop condition, made a variable more local.
Simplify loop by traversing Seq in reverse order.
Prepend rather than appending in Item lists.

The SV lists aren't order sensitive; and appending's costs are
quadratic compared to prepend's linear costs.
Canonify promiser name before testing if class is set

Also clean up some code; the function now asserts that
excluded is valid, and there is only one caller.

Add uncanonifed promiser to existing test case.

Fixes Redmine #6561
UMR-fix: EvalContext's ->pass was unset by default.

There's logging code (PromiseBanner) that reports the pass and
valgrind reported it as an uninitialized memory read.  So change
EvalContextNew() to use calloc and ditch a bunch of initializations
to NULL and false that this does for us.
Adjust test so that it fails for the right reasons.

Test passes if second cf-agent invokation also uses -K, which
is expected (and a crude workaround). But at least it shows that
the test is implemented correctly now.

Using ifelapsed => 0 in the method promise in bundle example
is necessary.

The regex can probably be made less aggressive, but it does the job.