Make SHOULD_RUN flag volatile.

The flag is changed from inside a signal handler.  When aggressive
optimizations are enabled, gcc removes the check in networking.c.
Don't call syslog() in signal handler.

The glibc implementation of syslog(3) is very much unsafe to call from
inside a signal handler: it allocates dynamic memory, takes out global
locks, and so on.  Before this commit, it was moderately easy to make
the process hang or crash by sending it a SIGINT.
Block all signals in new threads.

This prevents the signal handler from getting invoked in another thread.
It's not super harmful but it stops ThreadSanitizer from complaining.
Call flush_thread() from same thread on shutdown.

There is no need to spawn a new thread, just execute the flush from the
main thread.  Avoids missed metrics when hitting the RLIMIT_NPROC limit
on shutdown.
Handle EAGAIN from pthread_create().

Try to handle EAGAIN errors from pthread_create() when hitting the
RLIMIT_NPROC resource limit.  This patch merely restores the retired
metrics in the hope that a future call to pthread_create() succeeds.
Merge pull request #87 from bnoordhuis/fixups

Thread-safety / signal-safety fixups