From 8072bdcaa4445359051fed443be3d702f20807e0 Mon Sep 17 00:00:00 2001 From: Colin Patrick McCabe Date: Mon, 15 Aug 2011 20:42:57 -0700 Subject: [PATCH] Fix bug in turning off logging. Remove log_dir. 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 --- src/common/DoutStreambuf.cc | 48 +++++++---------------------------- src/common/common_init.cc | 1 + src/common/config.cc | 3 +-- src/common/config.h | 1 - src/global/global_init.cc | 6 ----- src/perfglue/heap_profiler.cc | 21 ++++++++++++--- 6 files changed, 29 insertions(+), 51 deletions(-) diff --git a/src/common/DoutStreambuf.cc b/src/common/DoutStreambuf.cc index dd07ee2f95a10..7962e43401bbe 100644 --- a/src/common/DoutStreambuf.cc +++ b/src/common/DoutStreambuf.cc @@ -274,7 +274,7 @@ const char** DoutStreambuf:: 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 &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:: _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; } diff --git a/src/common/common_init.cc b/src/common/common_init.cc index 95d64235090f7..eb80bbb3eaad9 100644 --- a/src/common/common_init.cc +++ b/src/common/common_init.cc @@ -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; diff --git a/src/common/config.cc b/src/common/config.cc index 9dc56268bcf70..76492864f880e 100644 --- a/src/common/config.cc +++ b/src/common/config.cc @@ -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& 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"); diff --git a/src/common/config.h b/src/common/config.h index 76bd7059302a8..0fffae842fa0b 100644 --- a/src/common/config.h +++ b/src/common/config.h @@ -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; diff --git a/src/global/global_init.cc b/src/global/global_init.cc index d24aaaa31546a..9b2deda15c2c0 100644 --- a/src/global/global_init.cc +++ b/src/global/global_init.cc @@ -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); diff --git a/src/perfglue/heap_profiler.cc b/src/perfglue/heap_profiler.cc index 066315cd21820..b2aa67f07359e 100644 --- a/src/perfglue/heap_profiler.cc +++ b/src/perfglue/heap_profiler.cc @@ -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); -- 2.39.5