Define the location of the config file only once

This commit is contained in:
Philip Rinn 2019-12-03 11:11:05 +01:00 committed by GitHub
parent 3fcc69f1cd
commit 6d0ecd8394
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 7 deletions

View File

@ -99,13 +99,10 @@ void bootstrap()
// and we want that to happen early on.
PlcConfig config;
// We just assume that the file we are reading with the
// configuration information in in the etc subfolder and use
// a relative path to find it.
const char* config_path = "../etc/config.ini";
if (ini_parse(config_path, config_handler, &config) < 0)
// Try to read the config file
if (ini_parse(oplc::config_file, config_handler, &config) < 0)
{
spdlog::info("Config file {} could not be read", config_path);
spdlog::info("Config file {} could not be read", oplc::config_file);
// If we don't have the config file, then default to always
// starting the interactive server.
config.services.push_back("interactive");

View File

@ -28,6 +28,9 @@
namespace oplc
{
/// Define location of config file once so others can use it
static const char* config_file = "../etc/config.ini";
/// Convert a boolean value in the INI file to a boolean.
/// The value must be "true", otherwise it is interpreted as false.
/// @param value the value to convert.
@ -122,7 +125,7 @@ typedef std::unique_ptr<std::istream, std::function<void(std::istream*)>> config
inline config_stream open_config()
{
return config_stream(
new std::ifstream("../etc/config.ini"),
new std::ifstream(config_file),
[] (std::istream* s)
{
reinterpret_cast<std::ifstream*>(s)->close();