From 360f823fac2811df0f926a33151ad05bae63f13a Mon Sep 17 00:00:00 2001 From: Radoslaw Zarzynski Date: Tue, 13 Feb 2018 16:09:55 +0100 Subject: [PATCH] log: prohibit negative values for debug_* configurables. Signed-off-by: Radoslaw Zarzynski --- src/common/config.cc | 7 ++++++- src/log/SubsystemMap.h | 13 ++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/common/config.cc b/src/common/config.cc index e16db0fe322..6ab7fc47f5f 100644 --- a/src/common/config.cc +++ b/src/common/config.cc @@ -325,8 +325,13 @@ int md_config_t::parse_config_files_impl(const std::list &conf_file int log, gather; int r = sscanf(val.c_str(), "%d/%d", &log, &gather); if (r >= 1) { - if (r < 2) + if (r < 2) { gather = log; + } + if (log < 0 || gather < 0) { + cerr << "ERROR for " << as_option << "." + << "log nor gather levels cannot be negative!"; + } // cout << "config subsys " << subsys.get_name(o) << " log " << log << " gather " << gather << std::endl; subsys.set_log_level(o, log); subsys.set_gather_level(o, gather); diff --git a/src/log/SubsystemMap.h b/src/log/SubsystemMap.h index 508263d1ba6..94d5d382b55 100644 --- a/src/log/SubsystemMap.h +++ b/src/log/SubsystemMap.h @@ -71,14 +71,21 @@ public: bool should_gather() { static_assert(SubV < get_num(), "wrong subsystem ID"); static_assert(LvlV >= -1 && LvlV <= 200); - return LvlV <= m_gather_levels[SubV]; + + if constexpr (LvlV <= 0) { + // handle the -1 and 0 levels entirely at compile-time. + // Such debugs are intended be gathered regardless even + // of the user configuration. + return true; + } else { + return LvlV <= static_cast(m_gather_levels[SubV]); + } } bool should_gather(const unsigned sub, int level) { assert(sub < m_subsys.size()); - return level <= m_gather_levels[sub]; + return level <= static_cast(m_gather_levels[sub]); } - // TODO(rzarzynski): verify the -1 case void set_log_level(unsigned subsys, uint8_t log) { assert(subsys < m_subsys.size()); -- 2.39.5