char *buf = NULL;
FILE *fp = fopen(fname.c_str(), "r");
if (!fp) {
- ret = errno;
+ ret = -errno;
ostringstream oss;
oss << "read_conf: failed to open '" << fname << "': " << cpp_strerror(ret);
errors->push_back(oss.str());
struct stat st_buf;
if (fstat(fileno(fp), &st_buf)) {
- ret = errno;
+ ret = -errno;
ostringstream oss;
oss << "read_conf: failed to fstat '" << fname << "': " << cpp_strerror(ret);
errors->push_back(oss.str());
if (fread(buf, 1, sz, fp) != sz) {
if (ferror(fp)) {
- ret = errno;
+ ret = -errno;
ostringstream oss;
oss << "read_conf: fread error while reading '" << fname << "': "
<< cpp_strerror(ret);
md_config_t::
md_config_t()
- : cf(NULL)
{
//
// Note: because our md_config_t structure is a global, the memory used to
md_config_t::
~md_config_t()
{
- delete cf;
- cf = NULL;
}
int md_config_t::
std::deque<std::string> *parse_errors)
{
// open new conf
- list<string>::const_iterator c = conf_files.begin();
- if (c == conf_files.end())
- return -EINVAL;
- while (true) {
- if (c == conf_files.end())
- return -EINVAL;
- ConfFile *cf_ = new ConfFile();
- int res = cf_->parse_file(c->c_str(), parse_errors);
- if (res == 0) {
- cf = cf_;
+ list<string>::const_iterator c;
+ for (c = conf_files.begin(); c != conf_files.end(); ++c) {
+ cf.clear();
+ int ret = cf.parse_file(c->c_str(), parse_errors);
+ if (ret == 0)
break;
- }
- delete cf_;
- if (res == -EDOM)
- return -EDOM;
- ++c;
+ else if (ret != -ENOENT)
+ return ret;
}
+ if (c == conf_files.end())
+ return -EINVAL;
std::vector <std::string> my_sections;
get_my_sections(my_sections);
std::string val;
for (std::vector<const char*>::iterator i = args.begin(); i != args.end(); ) {
if (ceph_argparse_flag(args, i, "--show_conf", (char*)NULL)) {
- if (cf) {
- cerr << *cf << std::endl;
- }
- else {
- cerr << "(no conf loaded)" << std::endl;
- }
+ cerr << cf << std::endl;
_exit(0);
}
else if (ceph_argparse_flag(args, i, "--foreground", "-f", (char*)NULL)) {
int md_config_t::
get_all_sections(std::vector <std::string> §ions)
{
- if (!cf)
- return -EDOM;
- for (ConfFile::const_section_iter_t s = cf->sections_begin();
- s != cf->sections_end(); ++s) {
+ for (ConfFile::const_section_iter_t s = cf.sections_begin();
+ s != cf.sections_end(); ++s) {
sections.push_back(s->first);
}
return 0;
}
-bool md_config_t::
-have_conf_file() const
-{
- return !!cf;
-}
-
int md_config_t::
get_val_from_conf_file(const std::vector <std::string> §ions,
const char *key, std::string &out, bool emeta) const
{
- if (!cf)
- return -EDOM;
std::vector <std::string>::const_iterator s = sections.begin();
std::vector <std::string>::const_iterator s_end = sections.end();
for (; s != s_end; ++s) {
- int ret = cf->read(s->c_str(), key, out);
+ int ret = cf.read(s->c_str(), key, out);
if (ret == 0) {
if (emeta)
expand_meta(out);
#include <vector>
#include <map>
-#include "include/assert.h"
-
+#include "common/ConfUtils.h"
#include "common/Mutex.h"
+#include "include/assert.h"
+#include "msg/msg_types.h"
#define OSD_REP_PRIMARY 0
#define OSD_REP_SPLAY 1
#define OSD_REP_CHAIN 2
+struct EntityName;
-#include "msg/msg_types.h"
+class config_option;
-struct EntityName;
+extern const char *CEPH_CONF_FILE_DEFAULT;
enum log_to_stderr_t {
LOG_TO_STDERR_NONE = 0,
LOG_TO_STDERR_ALL = 2,
};
-struct ConfFile;
-class config_option;
-
-extern const char *CEPH_CONF_FILE_DEFAULT;
-
struct md_config_t
{
public:
// Return a list of all sections
int get_all_sections(std::vector <std::string> §ions);
- bool have_conf_file() const;
-
// Get a value from the configuration file that we read earlier.
// Metavariables will be expanded if emeta is true.
int get_val_from_conf_file(const std::vector <std::string> §ions,
int set_val_impl(const char *val, const config_option *opt);
// The configuration file we read, or NULL if we haven't read one.
- ConfFile *cf;
+ ConfFile cf;
public:
std::string host;
cerr << "unable to parse addrs in '" << g_conf.mon_host << "'" << std::endl;
}
- // config file?
- if (!g_conf.have_conf_file()) {
- cerr << "Unable to find any monitors in the configuration "
- << "file, because there is no configuration file. "
- << "Please specify monitors via -m monaddr or -c ceph.conf" << std::endl;
- return -ENOENT;
- }
-
// What monitors are in the config file?
std::vector <std::string> sections;
int ret = g_conf.get_all_sections(sections);