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
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_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 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 @@
 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 @@
     }
     else // this is a disable request
     {
-        fs::remove(filePath);
+        // write '*.* ~' - this causes rsyslog to discard all messages
+        stream << "*.* ~";
     }
 
     restart();
@@ -144,11 +130,6 @@
 
 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 @@
 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 @@
     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 @@
     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