From: Davin McCall Date: Sat, 18 Jun 2016 19:21:06 +0000 (+0100) Subject: Add a method to discard the console log buffer contents. X-Git-Tag: v0.03~9 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=bdef1606c63fb7881c16baa7665ce9bb1e096870;p=oweals%2Fdinit.git Add a method to discard the console log buffer contents. --- diff --git a/src/dinit-log.cc b/src/dinit-log.cc index 292e780..c9ec5a7 100644 --- a/src/dinit-log.cc +++ b/src/dinit-log.cc @@ -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 diff --git a/src/dinit-log.h b/src/dinit-log.h index 5f1d51b..88fdc54 100644 --- a/src/dinit-log.h +++ b/src/dinit-log.h @@ -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;