Fix logging

Fix #98

1. volatile doesn't guarantee thread-safe, and there are time-of-check to time-of-use issue
2. 0 is valid file descriptor value
3. rist_get_global_logging_settings() has the TOCTOU problem
4. use PTHREAD_MUTEX_INITIALIZER when available to avoid the overhead of pthread_once()
5. fix memory leaks in error path
7 jobs for fix-logging in 2 minutes and 43 seconds (queued for 3 seconds)