diff options
author | Deepak Kodihalli <dkodihal@in.ibm.com> | 2018-08-28 07:47:11 -0500 |
---|---|---|
committer | Deepak Kodihalli <dkodihal@in.ibm.com> | 2018-08-29 03:45:17 -0500 |
commit | 9fab279fb38ab6b391503ce89aceb917ec35efa9 (patch) | |
tree | 032b30bdbed93089cea0eda9ecc7023386290bab | |
parent | 4db8146d529ea7c886bc88f922507c80e5570eae (diff) | |
download | phosphor-logging-9fab279fb38ab6b391503ce89aceb917ec35efa9.tar.gz phosphor-logging-9fab279fb38ab6b391503ce89aceb917ec35efa9.zip |
phosphor-rsyslog-conf: implement restore
Upon startup, if a remote logging config exists, relay that information
into appropriate D-Bus properties.
Change-Id: Ib873667a50f0c8a6af6a3b571f68d6075808ed10
Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
-rw-r--r-- | phosphor-rsyslog-config/server-conf.cpp | 24 | ||||
-rw-r--r-- | phosphor-rsyslog-config/server-conf.hpp | 19 |
2 files changed, 41 insertions, 2 deletions
diff --git a/phosphor-rsyslog-config/server-conf.cpp b/phosphor-rsyslog-config/server-conf.cpp index 1b46965..0b5bc62 100644 --- a/phosphor-rsyslog-config/server-conf.cpp +++ b/phosphor-rsyslog-config/server-conf.cpp @@ -2,7 +2,6 @@ #include "utils.hpp" #include "xyz/openbmc_project/Common/error.hpp" #include <fstream> -#include <phosphor-logging/log.hpp> #include <phosphor-logging/elog.hpp> #if __has_include("../../usr/include/phosphor-logging/elog-errors.hpp") #include "../../usr/include/phosphor-logging/elog-errors.hpp" @@ -128,5 +127,28 @@ bool Server::addressValid(const std::string& address) return true; } +void Server::restore(const char* filePath) +{ + std::fstream stream(filePath, std::fstream::in); + std::string line; + + getline(stream, line); + + // Ignore if line is commented + if ('#' != line.at(0)) + { + auto pos = line.find(':'); + if (pos != std::string::npos) + { + //"*.* @@<address>:<port>" + constexpr auto start = 6; // Skip "*.* @@" + auto serverAddress = line.substr(start, pos - start); + auto serverPort = line.substr(pos + 1); + NetworkClient::address(std::move(serverAddress)); + NetworkClient::port(std::stoul(serverPort)); + } + } +} + } // namespace rsyslog_config } // namespace phosphor diff --git a/phosphor-rsyslog-config/server-conf.hpp b/phosphor-rsyslog-config/server-conf.hpp index 795cfb6..0f67f30 100644 --- a/phosphor-rsyslog-config/server-conf.hpp +++ b/phosphor-rsyslog-config/server-conf.hpp @@ -3,6 +3,7 @@ #include <sdbusplus/bus.hpp> #include <sdbusplus/server/object.hpp> #include <string> +#include <phosphor-logging/log.hpp> #include "xyz/openbmc_project/Network/Client/server.hpp" namespace phosphor @@ -10,6 +11,7 @@ namespace phosphor namespace rsyslog_config { +using namespace phosphor::logging; using NetworkClient = sdbusplus::xyz::openbmc_project::Network::server::Client; using Iface = sdbusplus::server::object::object<NetworkClient>; @@ -37,9 +39,19 @@ class Server : public Iface Server(sdbusplus::bus::bus& bus, const std::string& path, const char* filePath) : - Iface(bus, path.c_str()), + Iface(bus, path.c_str(), true), configFilePath(filePath) { + try + { + restore(configFilePath.c_str()); + } + catch(const std::exception& e) + { + log<level::ERR>(e.what()); + } + + emit_object_added(); } using NetworkClient::address; @@ -75,6 +87,11 @@ class Server : public Iface */ bool addressValid(const std::string& address); + /** @brief Populate existing config into D-Bus properties + * @param[in] filePath - rsyslog config file path + */ + void restore(const char* filePath); + std::string configFilePath{}; }; |