Loading src/logger.hpp +4 −0 Original line number Original line Diff line number Diff line Loading @@ -131,6 +131,10 @@ public: return global_logger(); return global_logger(); } } static inline void destroy_global_logger() { global_logger().reset(); } // some macros to make it more convenient to use the global logger // some macros to make it more convenient to use the global logger #define LOGGER_INFO(...) \ #define LOGGER_INFO(...) \ do { \ do { \ Loading src/urd.cpp +17 −2 Original line number Original line Diff line number Diff line Loading @@ -94,8 +94,23 @@ pid_t urd::daemonize() { return 0; return 0; } } // We need to destroy the global logger before calling fork. Otherwise the // logger will not function properly since its internal thread will not // be duplicated by fork(). Furthermore, if we don't destroy pre-fork() // and attempt to replace it post-fork(), the logger destructor will attempt // to join the (now invalid) thread and end up blocking forever. To avoid // this (and since we want to be able to output messages from all // processes), we destroy it now and recreate it post-fork() both in the // parent process and in the child. logger::destroy_global_logger(); /* Fork off the parent process */ /* Fork off the parent process */ if((pid = fork()) < 0) { pid = fork(); // re-initialize logging facilities (post-fork) init_logger(); if(pid < 0) { LOGGER_ERRNO("Failed to create child process"); LOGGER_ERRNO("Failed to create child process"); exit(EXIT_FAILURE); exit(EXIT_FAILURE); } } Loading Loading @@ -1536,7 +1551,7 @@ urd_error urd::check_shutdown() { int urd::run() { int urd::run() { // initialize logging facilities // initialize logging facilities (pre-fork) init_logger(); init_logger(); // validate settings // validate settings Loading Loading
src/logger.hpp +4 −0 Original line number Original line Diff line number Diff line Loading @@ -131,6 +131,10 @@ public: return global_logger(); return global_logger(); } } static inline void destroy_global_logger() { global_logger().reset(); } // some macros to make it more convenient to use the global logger // some macros to make it more convenient to use the global logger #define LOGGER_INFO(...) \ #define LOGGER_INFO(...) \ do { \ do { \ Loading
src/urd.cpp +17 −2 Original line number Original line Diff line number Diff line Loading @@ -94,8 +94,23 @@ pid_t urd::daemonize() { return 0; return 0; } } // We need to destroy the global logger before calling fork. Otherwise the // logger will not function properly since its internal thread will not // be duplicated by fork(). Furthermore, if we don't destroy pre-fork() // and attempt to replace it post-fork(), the logger destructor will attempt // to join the (now invalid) thread and end up blocking forever. To avoid // this (and since we want to be able to output messages from all // processes), we destroy it now and recreate it post-fork() both in the // parent process and in the child. logger::destroy_global_logger(); /* Fork off the parent process */ /* Fork off the parent process */ if((pid = fork()) < 0) { pid = fork(); // re-initialize logging facilities (post-fork) init_logger(); if(pid < 0) { LOGGER_ERRNO("Failed to create child process"); LOGGER_ERRNO("Failed to create child process"); exit(EXIT_FAILURE); exit(EXIT_FAILURE); } } Loading Loading @@ -1536,7 +1551,7 @@ urd_error urd::check_shutdown() { int urd::run() { int urd::run() { // initialize logging facilities // initialize logging facilities (pre-fork) init_logger(); init_logger(); // validate settings // validate settings Loading