std::ostream *warnings,
int flags)
{
-
if (safe_to_start_threads)
return -ENOSYS;
// open new conf
string conffile;
for (auto& fn : get_conffile_paths(values, conf_files_str, warnings, flags)) {
+ bufferlist bl;
+ std::string error;
+ if (bl.read_file(fn.c_str(), &error)) {
+ parse_error = error;
+ continue;
+ }
ostringstream oss;
- int ret = cf.parse_file(fn.c_str(), &oss);
+ int ret = parse_buffer(values, tracker, bl.c_str(), bl.length(), &oss);
if (ret == 0) {
parse_error.clear();
conffile = fn;
break;
- } else {
- parse_error = oss.str();
- if (ret != -ENOENT) {
- return ret;
- }
+ }
+ parse_error = oss.str();
+ if (ret != -ENOENT) {
+ return ret;
}
}
// it must have been all ENOENTs, that's the only way we got here
- if (conffile.empty())
+ if (conffile.empty()) {
return -ENOENT;
-
+ }
if (values.cluster.empty()) {
values.cluster = get_cluster_name(conffile.c_str());
}
+ return 0;
+}
- std::vector<std::string> my_sections = get_my_sections(values);
+int
+md_config_t::parse_buffer(ConfigValues& values,
+ const ConfigTracker& tracker,
+ const char* buf, size_t len,
+ std::ostream* warnings)
+{
+ if (!cf.parse_buffer(string_view{buf, len}, warnings)) {
+ return -EINVAL;
+ }
+ const auto my_sections = get_my_sections(values);
for (const auto &i : schema) {
const auto &opt = i.second;
std::string val;
- int ret = _get_val_from_conf_file(my_sections, opt.name, val);
- if (ret == 0) {
- std::string error_message;
- int r = _set_val(values, tracker, val, opt, CONF_FILE, &error_message);
- if (warnings != nullptr && (r < 0 || !error_message.empty())) {
- *warnings << "parse error setting '" << opt.name << "' to '" << val
- << "'";
+ if (_get_val_from_conf_file(my_sections, opt.name, val)) {
+ continue;
+ }
+ std::string error_message;
+ if (_set_val(values, tracker, val, opt, CONF_FILE, &error_message) < 0) {
+ if (warnings != nullptr) {
+ *warnings << "parse error setting " << std::quoted(opt.name)
+ << " to " << std::quoted(val);
if (!error_message.empty()) {
*warnings << " (" << error_message << ")";
}
- *warnings << std::endl;
+ *warnings << '\n';
}
}
}
int parse_config_files(ConfigValues& values, const ConfigTracker& tracker,
const char *conf_files,
std::ostream *warnings, int flags);
-
+ int parse_buffer(ConfigValues& values, const ConfigTracker& tracker,
+ const char* buf, size_t len,
+ std::ostream *warnings);
// Absorb config settings from the environment
void parse_env(unsigned entity_type,
ConfigValues& values, const ConfigTracker& tracker,
// for those want to reexpand special meta, e.g, $pid
bool finalize_reexpand_meta(ConfigValues& values,
const ConfigTracker& tracker);
-private:
+
std::list<std::string> get_conffile_paths(const ConfigValues& values,
const char *conf_files,
std::ostream *warnings,
int flags) const;
+private:
static std::string get_cluster_name(const char* conffile_path);
// The configuration file we read, or NULL if we haven't read one.
ConfFile cf;
$ env CEPH_CONF=from-env ceph-conf -s foo bar
did not load config file, using default settings.
.* \-1 Errors while parsing config file! (re)
- .* \-1 parse_file: filesystem error: .* file.size: (No such file or directory )?\[from-env\] (re)
+ .* \-1 can't open from-env: \(2\) (No such file or directory)? (re)
.* \-1 Errors while parsing config file! (re)
- .* \-1 parse_file: filesystem error: .* file.size: (No such file or directory )?\[from-env\] (re)
+ .* \-1 can't open from-env: \(2\) (No such file or directory)? (re)
[1]
# command-line arguments should override environment