Preserve interrupted code's errno across signal handling.

git-svn-id: svn://daper.net/moc/trunk@2635 910807d9-36e0-0310-a014-e9ea483e2ba4
Thread ids cannot be compared using normal comparison operators.

Also note that the pthread_*() functions are not async-signal-safe
and therefore should not be used within a signal handler.  Fixing
this would require the creation of a new signal-handling thread,
so we will have to live with it for now.

git-svn-id: svn://daper.net/moc/trunk@2636 910807d9-36e0-0310-a014-e9ea483e2ba4
Handle EINTR from fflush(3).

Although there are comments which say that Linux will handle this
condition internally, the fflush(3) manpage says this can happen
via write(2) and since the overhead is minimal we'll play it safe.

git-svn-id: svn://daper.net/moc/trunk@2637 910807d9-36e0-0310-a014-e9ea483e2ba4
Refactor logging functions ahead of further work.

This also ensures that locking/unlocking and flushing is done
only once per call to logit() or log_init_stream().

git-svn-id: svn://daper.net/moc/trunk@2638 910807d9-36e0-0310-a014-e9ea483e2ba4
Avoid logging within signal handling functions.

Calling logit() from within signal handlers is unsafe for two
reasons: logging uses non-async-signal-safe functions, and
arbitrary re-entry can result in a deadlock on the logging mutex.

This commit is an interim solution.  The proper solution is to
create a new signal-handling thread where all signals can be
processed as normal execution code.

git-svn-id: svn://daper.net/moc/trunk@2639 910807d9-36e0-0310-a014-e9ea483e2ba4
Make common message formatting available to all functions.

This also removes potential buffer overflow exposures.

git-svn-id: svn://daper.net/moc/trunk@2640 910807d9-36e0-0310-a014-e9ea483e2ba4
Fix delayed client exit after the server exits in some circumstances.

If the server exits while the client is expecting to receive a data
response from it, then the EV_EXIT event gets queued but the expected
EV_DATA event never arrives.  The client will eventually exit with a
receive error when the socket gets closed, but if the socket was
inheritted by a long-running server child process (via On... scripts)
then it will not be closed until the child eventually exits and is
reaped by init(8).

Thanks to: Alex Merenstein

git-svn-id: svn://daper.net/moc/trunk@2641 910807d9-36e0-0310-a014-e9ea483e2ba4