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>
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;
}
}
- 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;
}
}
_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;
}
}
opath = _calculate_opath(conf);
if (opath.empty()) {
- ostringstream oss;
- oss << __func__ << ": _calculate_opath failed.\n";
- dout_emergency(oss.str());
return 1;
}
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;
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),
}
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");
std::string admin_socket;
std::string log_file;
- std::string log_dir;
std::string log_sym_dir;
int log_sym_history;
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);
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);