From d1a8af4a7d1ab9153b25b2611d4f00665ef0f9da Mon Sep 17 00:00:00 2001 From: Davin McCall Date: Sat, 16 Jan 2016 14:17:20 +0000 Subject: [PATCH] Introduce method to enable/disable console logging, instead of using a global variable. (introduce "enable_console_log(bool)", remove "log_to_console"). --- src/control.cc | 2 +- src/dinit-log.cc | 10 ++++++++-- src/dinit-log.h | 2 +- src/dinit.cc | 4 ++-- src/service.cc | 4 ++-- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/control.cc b/src/control.cc index f7c6541..3488b85 100644 --- a/src/control.cc +++ b/src/control.cc @@ -41,7 +41,7 @@ void ControlConn::processPacket() auto sd_type = static_cast(rbuf[1]); service_set->stop_all_services(sd_type); - log_to_console = true; + enable_console_log(true); char ackBuf[] = { DINIT_RP_ACK }; if (! queuePacket(ackBuf, 1)) return; diff --git a/src/dinit-log.cc b/src/dinit-log.cc index 8e031e7..88cdbec 100644 --- a/src/dinit-log.cc +++ b/src/dinit-log.cc @@ -2,8 +2,14 @@ #include "dinit-log.h" LogLevel log_level = LogLevel::WARN; -bool log_to_console = true; // whether we should output log messages to console -bool log_current_line; +static bool log_to_console = true; // whether we should output log messages to + // console immediately +static bool log_current_line; // Whether the current line is being logged + +void enable_console_log(bool enable) noexcept +{ + log_to_console = enable; +} // Log a message void log(LogLevel lvl, const char *msg) noexcept diff --git a/src/dinit-log.h b/src/dinit-log.h index b54664e..a11ebfe 100644 --- a/src/dinit-log.h +++ b/src/dinit-log.h @@ -16,7 +16,7 @@ enum class LogLevel { }; extern LogLevel log_level; -extern bool log_to_console; +void enable_console_log(bool do_enable) noexcept; void log(LogLevel lvl, const char *msg) noexcept; void logMsgBegin(LogLevel lvl, const char *msg) noexcept; diff --git a/src/dinit.cc b/src/dinit.cc index 6a2e78c..9e59dd4 100644 --- a/src/dinit.cc +++ b/src/dinit.cc @@ -458,7 +458,7 @@ void close_control_socket(struct ev_loop *loop) noexcept /* handle SIGINT signal (generated by kernel when ctrl+alt+del pressed) */ static void sigint_reboot_cb(struct ev_loop *loop, ev_signal *w, int revents) { - log_to_console = true; + enable_console_log(true); service_set->stop_all_services(ShutdownType::REBOOT); } @@ -476,6 +476,6 @@ static void sigquit_cb(struct ev_loop *loop, ev_signal *w, int revents) /* handle SIGTERM/SIGQUIT - stop all services (not used for system daemon) */ static void sigterm_cb(struct ev_loop *loop, ev_signal *w, int revents) { - log_to_console = true; + enable_console_log(true); service_set->stop_all_services(); } diff --git a/src/service.cc b/src/service.cc index a5c777a..7dab6bc 100644 --- a/src/service.cc +++ b/src/service.cc @@ -488,7 +488,7 @@ void ServiceRecord::acquiredConsole() noexcept releaseConsole(); } else if (startCheckDependencies(false)) { - log_to_console = false; + enable_console_log(false); allDepsStarted(true); } else { @@ -875,7 +875,7 @@ void ServiceRecord::queueForConsole() noexcept void ServiceRecord::releaseConsole() noexcept { - log_to_console = true; + enable_console_log(true); if (next_for_console != nullptr) { next_for_console->acquiredConsole(); } -- 2.25.1