From 788ddaa3191a238f9ef3bbaa09d3c72a920611fd Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 13 Nov 2009 10:47:52 -0800 Subject: [PATCH] config: accept list of possible conf file locations; include ./ceph.conf This makes './ceph -w' work with './vstart.sh -x'. --- src/config.cc | 22 +++++++++++++++------ src/mon/MonClient.cc | 47 ++++++++++++++++++++++---------------------- 2 files changed, 40 insertions(+), 29 deletions(-) diff --git a/src/config.cc b/src/config.cc index 3753660c336a5..1493c984006d2 100644 --- a/src/config.cc +++ b/src/config.cc @@ -32,6 +32,7 @@ stringtable g_stab; #include "include/atomic.h" +#include "include/str_list.h" #include "osd/osd_types.h" @@ -315,7 +316,7 @@ static struct config_option config_optionsp[] = { OPTION(log_sym_dir, 0, OPT_STR, 0), OPTION(log_to_stdout, 0, OPT_BOOL, true), OPTION(pid_file, 0, OPT_STR, "/var/run/ceph/$type.$id.pid"), - OPTION(conf, 'c', OPT_STR, "/etc/ceph/ceph.conf"), + OPTION(conf, 'c', OPT_STR, "/etc/ceph/ceph.conf, ~/ceph/config, ceph.conf"), OPTION(chdir, 0, OPT_STR, "/"), OPTION(fake_clock, 0, OPT_BOOL, false), OPTION(fakemessenger_serialize, 0, OPT_BOOL, true), @@ -1011,12 +1012,21 @@ void parse_startup_config_options(std::vector& args, bool isdaemon, if (cf) delete cf; - cf = new ConfFile(g_conf.conf); - - int ret = parse_config_file(cf, true); + // open new conf + string fn = g_conf.conf; + list ls; + get_str_list(fn, ls); + bool read_conf = false; + for (list::iterator p = ls.begin(); p != ls.end(); p++) { + cf = new ConfFile(p->c_str()); + read_conf = parse_config_file(cf, true); + if (read_conf) + break; + delete cf; + } - if (conf_specified && !ret) { - cerr << "error reading config file " << g_conf.conf << std::endl; + if (conf_specified && !read_conf) { + cerr << "error reading config file(s) " << g_conf.conf << std::endl; exit(1); } diff --git a/src/mon/MonClient.cc b/src/mon/MonClient.cc index 5aab9a41ba033..3c2d8963260aa 100644 --- a/src/mon/MonClient.cc +++ b/src/mon/MonClient.cc @@ -74,31 +74,32 @@ int MonClient::build_initial_monmap() } // config file? - ConfFile a(g_conf.conf); - ConfFile b("ceph.conf"); - ConfFile *c = 0; - - if (a.parse()) - c = &a; - else if (b.parse()) - c = &b; - if (c) { - static string monstr; - for (int i=0; i<15; i++) { - char monname[20]; - char *val = 0; - sprintf(monname, "mon%d", i); - c->read(monname, "mon addr", &val, 0); - if (!val || !val[0]) + string conf = g_conf.conf; + list ls; + get_str_list(conf, ls); + if (!ls.empty()) { + for (list::iterator p = ls.begin(); p != ls.end(); p++) { + ConfFile c(p->c_str()); + if (c.parse()) { + static string monstr; + for (int i=0; i<15; i++) { + char monname[20]; + char *val = 0; + sprintf(monname, "mon%d", i); + c.read(monname, "mon addr", &val, 0); + if (!val || !val[0]) + break; + + entity_inst_t inst; + if (!parse_ip_port(val, inst.addr)) { + cerr << "unable to parse conf's addr for " << monname << " (" << val << ")" << std::endl; + continue; + } + inst.name = entity_name_t::MON(monmap.mon_inst.size()); + monmap.add_mon(inst); + } break; - - entity_inst_t inst; - if (!parse_ip_port(val, inst.addr)) { - cerr << "unable to parse conf's addr for " << monname << " (" << val << ")" << std::endl; - continue; } - inst.name = entity_name_t::MON(monmap.mon_inst.size()); - monmap.add_mon(inst); } if (monmap.size()) return 0; -- 2.39.5