Add a method to discard the console log buffer contents.
authorDavin McCall <davmac@davmac.org>
Sat, 18 Jun 2016 19:21:06 +0000 (20:21 +0100)
committerDavin McCall <davmac@davmac.org>
Sat, 18 Jun 2016 19:21:06 +0000 (20:21 +0100)
src/dinit-log.cc
src/dinit-log.h

index 292e7805111b5e717c5effd252b64936e9e976aa..c9ec5a74620d604553a01b35d5a7d58040cbf882 100644 (file)
@@ -81,6 +81,13 @@ class BufferedLogStream : public EventLoop_t::FdWatcher
     {
         log_buffer.append(s, len);
     }
+    
+    // Discard buffer; call only when the stream isn't active.
+    void discard()
+    {
+        current_index = 0;
+        log_buffer.trim_to(0);
+    }
 };
 }
 
@@ -260,6 +267,10 @@ void enable_console_log(bool enable) noexcept
     }
 }
 
+void discard_console_log_buffer() noexcept
+{
+    log_stream[DLOG_CONS].discard();
+}
 
 // Variadic method to calculate the sum of string lengths:
 static int sum_length(const char *arg) noexcept
index 5f1d51bfba8b0a862c5b3d264088a7565dedb162..88fdc54be48f040ae5bf14938351057da47c14e5 100644 (file)
@@ -22,6 +22,7 @@ void enable_console_log(bool do_enable) noexcept;
 void init_log(ServiceSet *sset);
 void setup_main_log(int fd);
 bool is_log_flushed() noexcept;
+void discard_console_log_buffer() noexcept;
 
 void log(LogLevel lvl, const char *msg) noexcept;
 void logMsgBegin(LogLevel lvl, const char *msg) noexcept;