From e165ea956c5557c2b470869d252c80744227b00f Mon Sep 17 00:00:00 2001 From: Deepak Kodihalli Date: Fri, 11 Jan 2019 03:47:25 -0600 Subject: rsyslogd: don't start without actions Rsyslog is currently used only for remote logging. The daemon would run though (started by systemd) even when remote logging has not been configured. In other words, it would run without any actions. With Yocto 2.6, rsyslogd won't run without any actions. Hence, rsyslogd is now started only on the condition that the remote logging config file is present. Change-Id: Iae11d6912e60765ecb774b663d44b4e3c6f381a3 Signed-off-by: Deepak Kodihalli --- phosphor-rsyslog-config/Makefile.am | 3 ++- phosphor-rsyslog-config/server-conf.cpp | 22 ++++++++++++++++++++-- test/remote_logging_test_config.cpp | 21 +++++++++++++++++---- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/phosphor-rsyslog-config/Makefile.am b/phosphor-rsyslog-config/Makefile.am index 806e30b..438a745 100644 --- a/phosphor-rsyslog-config/Makefile.am +++ b/phosphor-rsyslog-config/Makefile.am @@ -15,7 +15,8 @@ phosphor_rsyslog_conf_LDADD = \ phosphor_rsyslog_conf_LDFLAGS = \ $(SDBUSPLUS_LIBS) \ - $(PHOSPHOR_DBUS_INTERFACES_LIBS) + $(PHOSPHOR_DBUS_INTERFACES_LIBS) \ + -lstdc++fs phosphor_rsyslog_conf_CXXFLAGS = \ $(SDBUSPLUS_CFLAGS) \ diff --git a/phosphor-rsyslog-config/server-conf.cpp b/phosphor-rsyslog-config/server-conf.cpp index 836e83b..e8da82e 100644 --- a/phosphor-rsyslog-config/server-conf.cpp +++ b/phosphor-rsyslog-config/server-conf.cpp @@ -15,6 +15,19 @@ #include +#if __has_include() +#include +#elif __has_include() +#include +namespace std +{ +// splice experimental::filesystem into std +namespace filesystem = std::experimental::filesystem; +} // namespace std +#else +#error filesystem not available +#endif + namespace phosphor { namespace rsyslog_config @@ -23,6 +36,7 @@ namespace rsyslog_config namespace utils = phosphor::rsyslog_utils; using namespace phosphor::logging; using namespace sdbusplus::xyz::openbmc_project::Common::Error; +namespace fs = std::filesystem; std::string Server::address(std::string value) { @@ -103,8 +117,7 @@ void Server::writeConfig(const std::string& serverAddress, uint16_t serverPort, } else // this is a disable request { - // write '#*.* @@remote-host:port' - stream << "#*.* @@remote-host:port"; + fs::remove(filePath); } restart(); @@ -130,6 +143,11 @@ bool Server::addressValid(const std::string& address) void Server::restore(const char* filePath) { + if (!fs::exists(filePath)) + { + return; + } + std::fstream stream(filePath, std::fstream::in); std::string line; diff --git a/test/remote_logging_test_config.cpp b/test/remote_logging_test_config.cpp index a4c6207..b34a43f 100644 --- a/test/remote_logging_test_config.cpp +++ b/test/remote_logging_test_config.cpp @@ -3,6 +3,19 @@ #include #include +#if __has_include() +#include +#elif __has_include() +#include +namespace std +{ +// splice experimental::filesystem into std +namespace filesystem = std::experimental::filesystem; +} // namespace std +#else +#error filesystem not available +#endif + namespace phosphor { namespace logging @@ -21,13 +34,13 @@ std::string getConfig(const char* filePath) TEST_F(TestRemoteLogging, testOnlyAddress) { config->address("1.1.1.1"); - EXPECT_EQ(getConfig(configFilePath.c_str()), "#*.* @@remote-host:port"); + EXPECT_EQ(fs::exists(configFilePath.c_str()), false); } TEST_F(TestRemoteLogging, testOnlyPort) { config->port(100); - EXPECT_EQ(getConfig(configFilePath.c_str()), "#*.* @@remote-host:port"); + EXPECT_EQ(fs::exists(configFilePath.c_str()), false); } TEST_F(TestRemoteLogging, testGoodConfig) @@ -43,7 +56,7 @@ TEST_F(TestRemoteLogging, testClearAddress) config->port(100); EXPECT_EQ(getConfig(configFilePath.c_str()), "*.* @@1.1.1.1:100"); config->address(""); - EXPECT_EQ(getConfig(configFilePath.c_str()), "#*.* @@remote-host:port"); + EXPECT_EQ(fs::exists(configFilePath.c_str()), false); } TEST_F(TestRemoteLogging, testClearPort) @@ -52,7 +65,7 @@ TEST_F(TestRemoteLogging, testClearPort) config->port(100); EXPECT_EQ(getConfig(configFilePath.c_str()), "*.* @@1.1.1.1:100"); config->port(0); - EXPECT_EQ(getConfig(configFilePath.c_str()), "#*.* @@remote-host:port"); + EXPECT_EQ(fs::exists(configFilePath.c_str()), false); } } // namespace test -- cgit v1.2.1