1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

config: add Config::getIncludeDirs()

This commit is contained in:
Steffen Vogel 2021-02-19 06:39:47 +01:00
parent 4058941130
commit 1e7ea26dfe
2 changed files with 24 additions and 5 deletions

View file

@ -28,6 +28,7 @@
#include <functional>
#include <regex>
#include <filesystem>
#include <jansson.h>
#include <villas/node/config.h>
@ -76,6 +77,9 @@ protected:
/** Run a callback function for each string in the config */
json_t * walkStrings(json_t *in, str_walk_fcn_t cb);
/** Get the include dirs */
std::list<std::filesystem::path> getIncludeDirs() const;
public:
json_t *root;

View file

@ -142,6 +142,18 @@ json_t * Config::decode(FILE *f)
return root;
}
std::list<std::filesystem::path> Config::getIncludeDirs()
{
auto uri = fs::read_symlink(fs::path("/proc/self/fd") / std::to_string(fileno(f)));
if (isLocalFile(uri)) {
return {
uri.parent_path()
};
}
else
return { };
}
#ifdef WITH_CONFIG
json_t * Config::libconfigDecode(FILE *f)
{
@ -153,13 +165,16 @@ json_t * Config::libconfigDecode(FILE *f)
config_set_auto_convert(&cfg, 1);
/* Setup libconfig include path. */
auto uri = fs::read_symlink(fs::path("/proc/self/fd") / std::to_string(fileno(f)));
if (isLocalFile(uri)) {
const auto &inclDir = uri.parent_path();
auto inclDirs = getIncludeDirs();
if (inclDirs.size() > 0) {
logger->info("Setting include dir to: {}", inclDirs[0]);
logger->info("Setting include dir to: {}", inclDir);
config_set_include_dir(&cfg, inclDirs[0].c_str());
config_set_include_dir(&cfg, inclDir.c_str());
if (inclDirs.size() > 1) {
logger->warn("Ignoring all but the first include directories for libconfig");
logger->warn(" libconfig does not support more than a single include dir!");
}
}
/* Rewind before re-reading */