From d858570755d88e9a3708952827a99cc24f09f9ab Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Mon, 6 Nov 2017 16:01:23 +0800 Subject: [PATCH] mon/LogMonitor: "log last" should return up to n entries limit the # of returned entries to "num", and backoff the start iterator by one if it reaches the rend(). Signed-off-by: Kefu Chai (cherry picked from commit de14103f5201da69b360d9b01e249896d59376b3) --- src/mon/LogMonitor.cc | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/mon/LogMonitor.cc b/src/mon/LogMonitor.cc index 9052490246654..b52767f9bceb8 100644 --- a/src/mon/LogMonitor.cc +++ b/src/mon/LogMonitor.cc @@ -429,23 +429,24 @@ bool LogMonitor::preprocess_command(MonOpRequestRef op) }; auto rp = summary.tail.rbegin(); - while (num > 0 && rp != summary.tail.rend()) { + for (; num > 0 && rp != summary.tail.rend(); ++rp) { if (match(*rp)) { num--; } - ++rp; + } + if (rp == summary.tail.rend()) { + --rp; } ostringstream ss; - auto p = summary.tail.begin(); - for ( ; p != summary.tail.end(); ++p) { - if (!match(*p)) { + for (; rp != summary.tail.rbegin(); --rp) { + if (!match(*rp)) { continue; } if (f) { - f->dump_object("entry", *p); + f->dump_object("entry", *rp); } else { - ss << *p << "\n"; + ss << *rp << "\n"; } } if (f) { -- 2.39.5