summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSantosh Puranik <santosh.puranik@in.ibm.com>2019-05-22 05:25:30 -0500
committerSantosh Puranik <santosh.puranik@in.ibm.com>2019-05-27 10:55:06 +0530
commit0a0b5ea558adeb109a3ac52e55ad720e188adb90 (patch)
tree16de2650795f4164e7640a44b193c3d1777ff4f2
parentf59854e94b077630200117b390c4e943d588be31 (diff)
downloadphosphor-logging-0a0b5ea558adeb109a3ac52e55ad720e188adb90.tar.gz
phosphor-logging-0a0b5ea558adeb109a3ac52e55ad720e188adb90.zip
rsyslod: Change disable action
This commit changes the way remote logging is disabled. Prior to this, we would create/delete the RSYSLOG_SERVER_CONFIG_FILE to enable/disable remote logging. Deleting the file would cause systemd to spin while it tried to trigger the syslog service via socket activation. So this commit reverts commits 40a7406097c0b5b0670c5987f6fe8c902d65562d and e165ea956c5557c2b470869d252c80744227b00f and then: To disable remote logging, we now simply ask that rsyslog ignore all incoming messages. This is done by using a special '~' rule for all messages. Tested: -- Verified that systemd no longer spins while trying to activate rsyslog with default config. -- Verified that setting a remote logging server over the REST API still works. Signed-off-by: Santosh Puranik <santosh.puranik@in.ibm.com> Change-Id: Ife217a84395aaf32b775b7a84f85fc6310df3e7c
-rw-r--r--phosphor-rsyslog-config/Makefile.am3
-rw-r--r--phosphor-rsyslog-config/server-conf.cpp23
-rw-r--r--test/remote_logging_test_config.cpp21
3 files changed, 7 insertions, 40 deletions
diff --git a/phosphor-rsyslog-config/Makefile.am b/phosphor-rsyslog-config/Makefile.am
index 5453473..3a1aeff 100644
--- a/phosphor-rsyslog-config/Makefile.am
+++ b/phosphor-rsyslog-config/Makefile.am
@@ -15,8 +15,7 @@ phosphor_rsyslog_conf_LDADD = \
phosphor_rsyslog_conf_LDFLAGS = \
$(SDBUSPLUS_LIBS) \
- $(PHOSPHOR_DBUS_INTERFACES_LIBS) \
- -lstdc++fs
+ $(PHOSPHOR_DBUS_INTERFACES_LIBS)
phosphor_rsyslog_conf_CXXFLAGS = \
$(SDBUSPLUS_CFLAGS) \
diff --git a/phosphor-rsyslog-config/server-conf.cpp b/phosphor-rsyslog-config/server-conf.cpp
index 16955fc..716421b 100644
--- a/phosphor-rsyslog-config/server-conf.cpp
+++ b/phosphor-rsyslog-config/server-conf.cpp
@@ -15,19 +15,6 @@
#include <string>
-#if __has_include(<filesystem>)
-#include <filesystem>
-#elif __has_include(<experimental/filesystem>)
-#include <experimental/filesystem>
-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
@@ -36,7 +23,6 @@ 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)
{
@@ -108,7 +94,6 @@ uint16_t Server::port(uint16_t value)
void Server::writeConfig(const std::string& serverAddress, uint16_t serverPort,
const char* filePath)
{
- fs::create_directory(fs::path(filePath).parent_path());
std::fstream stream(filePath, std::fstream::out);
if (serverPort && !serverAddress.empty())
@@ -118,7 +103,8 @@ void Server::writeConfig(const std::string& serverAddress, uint16_t serverPort,
}
else // this is a disable request
{
- fs::remove(filePath);
+ // write '*.* ~' - this causes rsyslog to discard all messages
+ stream << "*.* ~";
}
restart();
@@ -144,11 +130,6 @@ 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 b34a43f..cba54ea 100644
--- a/test/remote_logging_test_config.cpp
+++ b/test/remote_logging_test_config.cpp
@@ -3,19 +3,6 @@
#include <fstream>
#include <string>
-#if __has_include(<filesystem>)
-#include <filesystem>
-#elif __has_include(<experimental/filesystem>)
-#include <experimental/filesystem>
-namespace std
-{
-// splice experimental::filesystem into std
-namespace filesystem = std::experimental::filesystem;
-} // namespace std
-#else
-#error filesystem not available
-#endif
-
namespace phosphor
{
namespace logging
@@ -34,13 +21,13 @@ std::string getConfig(const char* filePath)
TEST_F(TestRemoteLogging, testOnlyAddress)
{
config->address("1.1.1.1");
- EXPECT_EQ(fs::exists(configFilePath.c_str()), false);
+ EXPECT_EQ(getConfig(configFilePath.c_str()), "*.* ~");
}
TEST_F(TestRemoteLogging, testOnlyPort)
{
config->port(100);
- EXPECT_EQ(fs::exists(configFilePath.c_str()), false);
+ EXPECT_EQ(getConfig(configFilePath.c_str()), "*.* ~");
}
TEST_F(TestRemoteLogging, testGoodConfig)
@@ -56,7 +43,7 @@ TEST_F(TestRemoteLogging, testClearAddress)
config->port(100);
EXPECT_EQ(getConfig(configFilePath.c_str()), "*.* @@1.1.1.1:100");
config->address("");
- EXPECT_EQ(fs::exists(configFilePath.c_str()), false);
+ EXPECT_EQ(getConfig(configFilePath.c_str()), "*.* ~");
}
TEST_F(TestRemoteLogging, testClearPort)
@@ -65,7 +52,7 @@ TEST_F(TestRemoteLogging, testClearPort)
config->port(100);
EXPECT_EQ(getConfig(configFilePath.c_str()), "*.* @@1.1.1.1:100");
config->port(0);
- EXPECT_EQ(fs::exists(configFilePath.c_str()), false);
+ EXPECT_EQ(getConfig(configFilePath.c_str()), "*.* ~");
}
} // namespace test
OpenPOWER on IntegriCloud