]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: LogMonitor: handle boolean options consistently 5357/head
authorJoao Eduardo Luis <joao@suse.de>
Mon, 27 Jul 2015 20:17:31 +0000 (21:17 +0100)
committerJoao Eduardo Luis <joao@suse.de>
Fri, 28 Aug 2015 11:32:03 +0000 (12:32 +0100)
'mon_cluster_log_to_syslog' gets a string of key/value pairs, values
in the pair being booleans, and keys being optional (one can simply
specify the value). However, we weren't being consistent with the
boolean behavior when handling option values. e.g., the user expects
'1' and '0' to mean 'true' and 'false' respectively, and expects
'mon_cluster_log_to_syslog' to understand both '1' and '0', alongside
with 'true' and 'false'.

All values not 'true' or '1' will be considered 'false'.

Fixes: #12325
Signed-off-by: Joao Eduardo Luis <joao@suse.de>
src/mon/LogMonitor.cc
src/mon/LogMonitor.h

index c571c69f818fb8481dccb5fd007e89c77f5b812e..b5ab44712fd0b9b2e4b2ee8f040ab49896e9685f 100644 (file)
@@ -12,6 +12,8 @@
  * 
  */
 
+#include <boost/algorithm/string/predicate.hpp>
+
 #include <sstream>
 #include <syslog.h>
 
@@ -28,6 +30,7 @@
 #include "osd/osd_types.h"
 #include "common/errno.h"
 #include "common/config.h"
+#include "common/strtol.h"
 #include "include/assert.h"
 #include "include/str_list.h"
 #include "include/str_map.h"
@@ -673,6 +676,33 @@ string LogMonitor::log_channel_info::expand_channel_meta(
   return s;
 }
 
+bool LogMonitor::log_channel_info::do_log_to_syslog(const string &channel) {
+  string v = get_str_map_key(log_to_syslog, channel,
+                             &CLOG_CONFIG_DEFAULT_KEY);
+  // We expect booleans, but they are in k/v pairs, kept
+  // as strings, in 'log_to_syslog'. We must ensure
+  // compatibility with existing boolean handling, and so
+  // we are here using a modified version of how
+  // md_config_t::set_val_raw() handles booleans. We will
+  // accept both 'true' and 'false', but will also check for
+  // '1' and '0'. The main distiction between this and the
+  // original code is that we will assume everything not '1',
+  // '0', 'true' or 'false' to be 'false'.
+  bool ret = false;
+
+  if (boost::iequals(v, "false")) {
+    ret = false;
+  } else if (boost::iequals(v, "true")) {
+    ret = true;
+  } else {
+    std::string err;
+    int b = strict_strtol(v.c_str(), 10, &err);
+    ret = (err.empty() && b == 1);
+  }
+
+  return ret;
+}
+
 void LogMonitor::handle_conf_change(const struct md_config_t *conf,
                                     const std::set<std::string> &changed)
 {
index 6dcee8b85cbcb49d2781a2db68a7e525dc8a0d6b..4d31b66b3d13c65ca027b6513993efd3ce87d15b 100644 (file)
@@ -69,10 +69,7 @@ private:
     string expand_channel_meta(const string &input,
                                const string &change_to);
 
-    bool do_log_to_syslog(const string &channel) {
-      return (get_str_map_key(log_to_syslog, channel,
-                              &CLOG_CONFIG_DEFAULT_KEY) == "true");
-    }
+    bool do_log_to_syslog(const string &channel);
 
     string get_facility(const string &channel) {
       return get_str_map_key(syslog_facility, channel,