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.
Merge pull request #1965 from ediosyncratic/risk-fixes

Fixes for things that might actually break, plus some performance tweaks.