Introduce method to enable/disable console logging, instead of
authorDavin McCall <davmac@davmac.org>
Sat, 16 Jan 2016 14:17:20 +0000 (14:17 +0000)
committerDavin McCall <davmac@davmac.org>
Sat, 16 Jan 2016 14:17:20 +0000 (14:17 +0000)
using a global variable. (introduce "enable_console_log(bool)",
remove "log_to_console").

src/control.cc
src/dinit-log.cc
src/dinit-log.h
src/dinit.cc
src/service.cc

index f7c654119b6f9d4dc04fa217d3d81d553150e305..3488b859c29051896584ad93caf5046316583693 100644 (file)
@@ -41,7 +41,7 @@ void ControlConn::processPacket()
         auto sd_type = static_cast<ShutdownType>(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;
         
index 8e031e7fa57b378e4ab04f71a12b91d87268f80d..88cdbecf2af4554756980c65e7760f684aba2b14 100644 (file)
@@ -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
index b54664e8a0d55474edc39e2760e1d7a0ee91f28c..a11ebfeab408f7f5aa9ef2d54f8e4672d9a32e8e 100644 (file)
@@ -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;
index 6a2e78cef6f2674144f1dce63f3a91e47d2084e7..9e59dd44bac3d217924f98288334a9f9013b05b8 100644 (file)
@@ -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();
 }
index a5c777a73430e8a132ac017f71a31ea2d102aafa..7dab6bc17b6c7b2d9c2b61290a6400341cb1de39 100644 (file)
@@ -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();
     }