Fix logging implementation

- Block signals in logging routine (fix #3976)
- Prevent possible deadlock after fork (stdio locks internally)
  by creating a new FILE pointer per logging call (thread/stack local)
This commit is contained in:
topjohnwu
2021-03-06 13:55:30 -08:00
parent 15e27e54fb
commit 39982d57ef
2 changed files with 107 additions and 80 deletions

View File

@@ -8,7 +8,12 @@
#define UID_ROOT 0
#define UID_SHELL 2000
#define DISALLOW_COPY_AND_MOVE(clazz) \
clazz(const clazz &) = delete; \
clazz(clazz &&) = delete;
class mutex_guard {
DISALLOW_COPY_AND_MOVE(mutex_guard)
public:
explicit mutex_guard(pthread_mutex_t &m): mutex(&m) {
pthread_mutex_lock(mutex);
@@ -26,6 +31,7 @@ private:
template <class Func>
class run_finally {
DISALLOW_COPY_AND_MOVE(run_finally)
public:
explicit run_finally(const Func &fn) : fn(fn) {}
~run_finally() { fn(); }