Browse Source

[4062] Added environment protection in test ctor/dtor

Francis Dupont 9 years ago
parent
commit
5853bacc9b
1 changed files with 18 additions and 1 deletions
  1. 18 1
      src/lib/dhcpsrv/tests/daemon_unittest.cc

+ 18 - 1
src/lib/dhcpsrv/tests/daemon_unittest.cc

@@ -57,7 +57,12 @@ namespace {
 class DaemonTest : public ::testing::Test {
 class DaemonTest : public ::testing::Test {
 public:
 public:
     /// @brief Constructor
     /// @brief Constructor
-    DaemonTest() {
+    DaemonTest() : env_(0), copy_() {
+        // Take a copy of KEA_PIDFILE_DIR environment variable value
+        env_ = getenv("KEA_PIDFILE_DIR");
+        if (env_) {
+            copy_ = std::string(env_);
+        }
     }
     }
 
 
     /// @brief Destructor
     /// @brief Destructor
@@ -67,7 +72,19 @@ public:
     /// the default after each test completes.
     /// the default after each test completes.
     ~DaemonTest() {
     ~DaemonTest() {
         isc::log::setDefaultLoggingOutput();
         isc::log::setDefaultLoggingOutput();
+        // Restore KEA_PIDFILE_DIR environment variable value
+        env_ = getenv("KEA_PIDFILE_DIR");
+        if (!copy_.empty() && (!env_ || !copy_.compare(env_))) {
+            setenv("KEA_PIDFILE_DIR", copy_.c_str(), 1);
+        }
     }
     }
+
+private:
+    /// @brief KEA_PIDFILE_DIR environment variable value
+    char* env_;
+
+    /// @brief copy of KEA_PIDFILE_DIR environment variable value
+    std::string copy_;
 };
 };