]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Fix bug in turning off logging. Remove log_dir.
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Tue, 16 Aug 2011 03:42:57 +0000 (20:42 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Tue, 16 Aug 2011 03:58:23 +0000 (20:58 -0700)
Fix a bug that made it impossible to turn off logging to a file.

Remove the old "log_dir" setting. It has been deprecated for a long
time, and it adds a lot of complexity to the code.

heap_profiler: use the directory that log_file is in to construct a
profiler output file name. Don't use log_dir.

Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
src/common/DoutStreambuf.cc
src/common/common_init.cc
src/common/config.cc
src/common/config.h
src/global/global_init.cc
src/perfglue/heap_profiler.cc

index dd07ee2f95a1053eea4c1449baabcfdd956cd46f..7962e43401bbe179e3bcc5ce71da574f3674bd23 100644 (file)
@@ -274,7 +274,7 @@ const char** DoutStreambuf<charT, traits>::
 get_tracked_conf_keys() const
 {
   static const char *KEYS[] =
-       { "log_file", "log_dir", "log_sym_dir",
+       { "log_file", "log_sym_dir",
         "log_sym_history", "log_to_stderr",
         "log_to_syslog", "log_per_instance", NULL };
   return KEYS;
@@ -321,10 +321,8 @@ handle_conf_change(const md_config_t *conf, const std::set <std::string> &change
     }
   }
 
-  if ((!conf->log_file.empty()) || (!conf->log_dir.empty())) {
-    if (_read_ofile_config(conf) == 0) {
-      flags |= DOUTSB_FLAG_OFILE;
-    }
+  if (_read_ofile_config(conf) == 0) {
+    flags |= DOUTSB_FLAG_OFILE;
   }
 }
 
@@ -456,44 +454,19 @@ std::string DoutStreambuf<charT, traits>::
 _calculate_opath(const md_config_t *conf) const
 {
   // should hold the dout_lock here
-
-  // If conf->log_file was specified, that takes the highest priority
-  if (!conf->log_file.empty()) {
-    string log_file(normalize_relative(conf->log_file.c_str()));
-    if ((conf->log_per_instance) && (g_code_env == CODE_ENVIRONMENT_DAEMON)) {
-      ostringstream oss;
-      oss << log_file << "." << getpid();
-      return oss.str();
-    }
-    else
-      return log_file;
+  if (conf->log_file.empty()) {
+    // We don't want a log file.
+    return "";
   }
 
-  string log_dir;
-  if (conf->log_dir.empty())
-    log_dir = normalize_relative(".");
-  else
-    log_dir = normalize_relative(conf->log_dir.c_str());
-
+  string log_file(normalize_relative(conf->log_file.c_str()));
   if ((conf->log_per_instance) && (g_code_env == CODE_ENVIRONMENT_DAEMON)) {
-    char hostname[255];
-    memset(hostname, 0, sizeof(hostname));
-    int ret = gethostname(hostname, sizeof(hostname));
-    if (ret) {
-      int err = errno;
-      ostringstream oss;
-      oss << __func__ << ": error calling gethostname: " << cpp_strerror(err) << "\n";
-      dout_emergency(oss.str());
-      return "";
-    }
     ostringstream oss;
-    oss << log_dir << "/" << hostname << "." << getpid();
+    oss << log_file << "." << getpid();
     return oss.str();
   }
   else {
-    ostringstream oss;
-    oss << log_dir << "/" << conf->name.to_str() << ".log";
-    return oss.str();
+    return log_file;
   }
 }
 
@@ -519,9 +492,6 @@ _read_ofile_config(const md_config_t *conf)
 
   opath = _calculate_opath(conf);
   if (opath.empty()) {
-    ostringstream oss;
-    oss << __func__ << ": _calculate_opath failed.\n";
-    dout_emergency(oss.str());
     return 1;
   }
 
index 95d64235090f7bd51b3ac285d98da8fcc0ee5267..eb80bbb3eaad96f52a9df940dd5b48202a08e384 100644 (file)
@@ -53,6 +53,7 @@ CephContext *common_preinit(const CephInitParameters &iparams,
       if (!(flags & CINIT_FLAG_UNPRIVILEGED_DAEMON_DEFAULTS)) {
        conf->set_val_or_die("pid_file", "/var/run/ceph/$type.$id.pid");
        conf->set_val_or_die("admin_socket", "/var/run/ceph/$name.asok");
+       conf->set_val_or_die("log_file", "/var/log/ceph/$name.log");
       }
       conf->set_val_or_die("log_to_stderr", STRINGIFY(LOG_TO_STDERR_SOME));
       break;
index 9dc56268bcf70d943ac7f05082ace562b67277e7..76492864f880e3cf003c3884cfe8282fba17b53a 100644 (file)
@@ -130,7 +130,6 @@ struct config_option config_optionsp[] = {
   OPTION(daemonize, OPT_BOOL, false),
   OPTION(admin_socket, OPT_STR, ""),
   OPTION(log_file, OPT_STR, 0),
-  OPTION(log_dir, OPT_STR, 0),
   OPTION(log_sym_dir, OPT_STR, 0),
   OPTION(log_sym_history, OPT_INT, 10),
   OPTION(log_to_stderr, OPT_INT, LOG_TO_STDERR_ALL),
@@ -606,7 +605,7 @@ parse_argv(std::vector<const char*>& args)
     }
     else if (ceph_argparse_flag(args, i, "-d", (char*)NULL)) {
       set_val_or_die("daemonize", "false");
-      set_val_or_die("log_dir", "");
+      set_val_or_die("log_file", "");
       set_val_or_die("pid_file", "");
       set_val_or_die("log_sym_dir", "");
       set_val_or_die("log_sym_history", "0");
index 76bd7059302a853e17dbd792ffe4ce03b93615e5..0fffae842fa0be3a7b7c9d38dde3af8ffd2542ca 100644 (file)
@@ -176,7 +176,6 @@ public:
   std::string admin_socket;
 
   std::string log_file;
-  std::string log_dir;
   std::string log_sym_dir;
   int log_sym_history;
 
index d24aaaa31546aff8b798125d4690f7c090fd560e..9b2deda15c2c0ca28124e64380557ef7c3ebda69 100644 (file)
@@ -88,12 +88,6 @@ void global_init(std::vector < const char* >& args,
 
   conf->parse_argv(args); // argv override
 
-  if (code_env == CODE_ENVIRONMENT_DAEMON) {
-    if (conf->log_dir.empty() && conf->log_file.empty()) {
-       conf->set_val_or_die("log_file", "/var/log/ceph/$name.log");
-    }
-  }
-
   // Expand metavariables. Invoke configuration observers.
   conf->apply_changes(NULL);
 
index 066315cd21820637a3bb6f318b2899af65e8e3f0..b2aa67f07359eb1e5a605cceb2ee48c0996ea2fe 100644 (file)
@@ -47,12 +47,27 @@ bool ceph_heap_profiler_running()
   return IsHeapProfilerRunning();
 }
 
+static void get_profile_name(char *profile_name, int profile_name_len)
+{
+  char path[PATH_MAX];
+  snprintf(path, sizeof(path), g_conf->log_file.c_str());
+  char *last_slash = rindex(path, '/');
+
+  if (last_slash == NULL) {
+    snprintf(profile_name, profile_name_len, "./%s.profile",
+            g_conf->name.to_cstr());
+  }
+  else {
+    last_slash[1] = '\0';
+    snprintf(profile_name, profile_name_len, "%s/%s.profile",
+            path, g_conf->name.to_cstr());
+  }
+}
+
 void ceph_heap_profiler_start()
 {
   char profile_name[PATH_MAX];
-  snprintf(profile_name, sizeof(profile_name),
-          "%s/%s", g_conf->log_dir.empty() ? "." : g_conf->log_dir.c_str(),
-                                           g_conf->name.to_cstr());
+  get_profile_name(profile_name, sizeof(profile_name)); 
   generic_dout(0) << "turning on heap profiler with prefix "
                  << profile_name << dendl;
   HeapProfilerStart(profile_name);