Thanks Hans, I'll rewrite that part. -----Original Message----- From: Hans Nordeback <hans.nordeb...@ericsson.com> Date: Thursday, 20 September 2018 at 10:18 pm To: gary <gary....@dektech.com.au> Cc: <opensaf-devel@lists.sourceforge.net> Subject: Re: [PATCH 2/3] base: add config file reader [#2923]
Hi Gary, I think we need to replace the use of std::regex for now. /Thanks HansN On 09/20/2018 02:09 PM, Gary Lee wrote: > Hi Hans > > Just tested it with 4.9.3 and it works fine. > > It doesn't link with 4.8.5 > > config_file_reader.cc:(.text+0x1c8): undefined reference to `std::regex_token_iterator<__gnu_cxx::__normal_iterator<char const*, std::string>, char, std::regex_traits<char> >::regex_token_iterator(__gnu_cxx::__normal_iterator<char const*, std::string>, __gnu_cxx::__normal_iterator<char const*, std::string>, std::basic_regex<char, std::regex_traits<char> > const&, int, std::bitset<11ul>) > > Is it time to upgrade the gcc requirement? ( > > Gary > > -----Original Message----- > From: Hans Nordeback <hans.nordeb...@ericsson.com> > Date: Thursday, 20 September 2018 at 8:40 pm > To: gary <gary....@dektech.com.au> > Cc: <opensaf-devel@lists.sourceforge.net> > Subject: Re: [PATCH 2/3] base: add config file reader [#2923] > > ack, review only. Some comments below. /Thanks HansN > > > On 09/19/2018 05:42 AM, Gary Lee wrote: > > Some configuration attribute are read by OpenSAF daemons as > > environment variables. eg. > > > > export FMS_PROMOTE_ACTIVE_TIMER=0 > > > > There is no easy way to reload these values without a restart. > > > > ConfigFileReader will parse these files looking for 'export VAR=VAL' > > and store them into a map, so a daemon can reload configuration > > without a restart. > > --- > > src/base/Makefile.am | 2 ++ > > src/base/config_file_reader.cc | 43 ++++++++++++++++++++++++++++++++++ > > src/base/config_file_reader.h | 30 ++++++++++++++++++++++++ > > 3 files changed, 75 insertions(+) > > create mode 100644 src/base/config_file_reader.cc > > create mode 100644 src/base/config_file_reader.h > > > > diff --git a/src/base/Makefile.am b/src/base/Makefile.am > > index c7dd01900..ce93562e5 100644 > > --- a/src/base/Makefile.am > > +++ b/src/base/Makefile.am > > @@ -33,6 +33,7 @@ lib_libopensaf_core_la_LDFLAGS += \ > > lib_libopensaf_core_la_SOURCES += \ > > src/base/condition_variable.cc \ > > src/base/conf.cc \ > > + src/base/config_file_reader.cc \ > > src/base/daemon.c \ > > src/base/file_descriptor.cc \ > > src/base/file_notify.cc \ > > @@ -94,6 +95,7 @@ noinst_HEADERS += \ > > src/base/buffer.h \ > > src/base/condition_variable.h \ > > src/base/conf.h \ > > + src/base/config_file_reader.h \ > > src/base/daemon.h \ > > src/base/file_descriptor.h \ > > src/base/file_notify.h \ > > diff --git a/src/base/config_file_reader.cc b/src/base/config_file_reader.cc > > new file mode 100644 > > index 000000000..d22930505 > > --- /dev/null > > +++ b/src/base/config_file_reader.cc > > @@ -0,0 +1,43 @@ > > +/* -*- OpenSAF -*- > > + * > > + * Copyright Ericsson AB 2018 - All Rights Reserved. > > + * > > + * This program is distributed in the hope that it will be useful, but > > + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY > > + * or FITNESS FOR A PARTICULAR PURPOSE. This file and program are licensed > > + * under the GNU Lesser General Public License Version 2.1, February 1999. > > + * The complete license can be accessed from the following location: > > + * http://opensource.org/licenses/lgpl-license.php > > + * See the Copying file included with the OpenSAF distribution for full > > + * licensing terms. > > + * > > + */ > > + > > +#include <fstream> > > +#include <regex> > > +#include "base/config_file_reader.h" > > + > > +ConfigFileReader::SettingsMap ConfigFileReader::ParseFile(const std::string& filename) { > > + SettingsMap map; > > + std::ifstream file(filename); > > + std::string line; > > + > > + if (file.is_open()) { > > + while (getline(file, line)) { > > + // go through each line of the config file > > + // only process "export key=value" and ignore trailing comments > > + // note: value may be surrounded with quotes > [HansN] there were some issues found using std::regex with gcc 4.8.4 in > ticket #2165 but worked with newer compiler versions, check > the review comments for ticket #2165 > > + std::regex re("^export\\s*(\\w+)\\s*=\\s*([^#\\n]+)"); > > + std::sregex_token_iterator key_iter(line.begin(), line.end(), re, 1); > > + std::sregex_token_iterator value_iter(line.begin(), line.end(), re, 2); > > + std::sregex_token_iterator end; > > + > > + for (; key_iter != end && value_iter != end; ++key_iter, ++value_iter) { > > + // store key-value pairs into map > > + map[key_iter->str()] = value_iter->str(); > > + } > > + } > > + file.close(); > > + } > > + return map; > > +} > > diff --git a/src/base/config_file_reader.h b/src/base/config_file_reader.h > > new file mode 100644 > > index 000000000..cb281b7db > > --- /dev/null > > +++ b/src/base/config_file_reader.h > > @@ -0,0 +1,30 @@ > > +/* -*- OpenSAF -*- > > + * > > + * Copyright Ericsson AB 2018 - All Rights Reserved. > > + * > > + * This program is distributed in the hope that it will be useful, but > > + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY > > + * or FITNESS FOR A PARTICULAR PURPOSE. This file and program are licensed > > + * under the GNU Lesser General Public License Version 2.1, February 1999. > > + * The complete license can be accessed from the following location: > > + * http://opensource.org/licenses/lgpl-license.php > > + * See the Copying file included with the OpenSAF distribution for full > > + * licensing terms. > > + * > > + */ > > + > > +#ifndef BASE_CONFIG_FILE_READER_H_ > > +#define BASE_CONFIG_FILE_READER_H_ > > + > > +#include <map> > > +#include <string> > > + > > +class ConfigFileReader { > > + public: > [HansN] prefer alias declarations to typedefs, (i.e. using). > > + typedef std::map<std::string, std::string> SettingsMap; > > + > > + // parses OpenSAF 'config' files and return key-value pairs in a map > > + ConfigFileReader::SettingsMap ParseFile(const std::string& filename); > > +}; > > + > > +#endif /* BASE_CONFIG_FILE_READER_H */ > > > > _______________________________________________ Opensaf-devel mailing list Opensaf-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/opensaf-devel