Hi Gary, ack, code review only/Thanks HansN
On 2019-05-17 14:47, Gary Lee wrote:
> ConfigFileReader enables runtime 'reload' of .conf files.
> However, if the environment variable is surrounded by quotes,
> it adds the quotes to the value which is not the expected behaviour.
>
> export FOO="foo"
>
> FOO should contain just foo, not "foo".
> ---
> src/base/config_file_reader.cc | 15 +++++++++++++++
> src/osaf/consensus/consensus.cc | 1 +
> 2 files changed, 16 insertions(+)
>
> diff --git a/src/base/config_file_reader.cc b/src/base/config_file_reader.cc
> index 63cad7d..0132547 100644
> --- a/src/base/config_file_reader.cc
> +++ b/src/base/config_file_reader.cc
> @@ -36,6 +36,18 @@ static void trim(std::string& str) {
> right_trim(str);
> }
>
> +static void strip_quotes(std::string& str) {
> + // trim leading and trailing quotes
> + if (str.front() == '"' ||
> + str.front() == '\'') {
> + str.erase(0, 1); // delete first char
> + }
> + if (str.back() == '"' ||
> + str.back() == '\'') {
> + str.pop_back(); // delete last char
> + }
> +}
> +
> ConfigFileReader::SettingsMap ConfigFileReader::ParseFile(
> const std::string& filename) {
> const std::string prefix("export");
> @@ -80,6 +92,9 @@ ConfigFileReader::SettingsMap ConfigFileReader::ParseFile(
> std::string value = line.substr(equal + 1);
> trim(value);
>
> + strip_quotes(key);
> + strip_quotes(value);
> +
> map[key] = value;
> }
> file.close();
> diff --git a/src/osaf/consensus/consensus.cc b/src/osaf/consensus/consensus.cc
> index 480f7d2..0bebab2 100644
> --- a/src/osaf/consensus/consensus.cc
> +++ b/src/osaf/consensus/consensus.cc
> @@ -295,6 +295,7 @@ bool Consensus::ReloadConfiguration() {
> continue;
> }
> int rc;
> + TRACE("Setting '%s' to '%s'", kv.first.c_str(), kv.second.c_str());
> rc = setenv(kv.first.c_str(), kv.second.c_str(), 1);
> osafassert(rc == 0);
> }
_______________________________________________
Opensaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel