Skip to content

Commit

Permalink
log: prohibit negative values for debug_* configurables.
Browse files Browse the repository at this point in the history
Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
  • Loading branch information
rzarzynski committed Feb 27, 2018
1 parent 7b24a30 commit 676139a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/common/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,13 @@ int md_config_t::parse_config_files_impl(const std::list<std::string> &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);
Expand Down
13 changes: 10 additions & 3 deletions src/log/SubsystemMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,21 @@ class SubsystemMap {
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<int>(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<int>(m_gather_levels[sub]);
}

// TODO(rzarzynski): verify the -1 case
void set_log_level(unsigned subsys, uint8_t log)
{
assert(subsys < m_subsys.size());
Expand Down

0 comments on commit 676139a

Please sign in to comment.