Browse Source

[3687] Two minor changes as a result of code review.

PIDFile::write closes the stream before throwing an exception. Also,
remove the TESTNAME2 file before and after the test.
Marcin Siodelski 10 years ago
parent
commit
48888c80f0
2 changed files with 9 additions and 6 deletions
  1. 5 4
      src/lib/util/pid_file.cc
  2. 4 2
      src/lib/util/tests/pid_file_unittest.cc

+ 5 - 4
src/lib/util/pid_file.cc

@@ -75,13 +75,14 @@ PIDFile::write(int pid) const {
 
     // File is open, write the pid.
     fs << pid << std::endl;
-    if (!fs.good()) {
+
+    bool good = fs.good();
+    fs.close();
+
+    if (!good()) {
         isc_throw(PIDFileError, "Unable to write to PID file '"
                   << filename_ << "'");
     }
-
-    // That's it
-    fs.close();
 }
 
 void

+ 4 - 2
src/lib/util/tests/pid_file_unittest.cc

@@ -19,8 +19,9 @@
 namespace {
 using namespace isc::util;
 
-#define TESTNAME "pid_file.test"
-#define TESTNAME2 "pid_file.test.2"
+// Filenames used for testing.
+const char* TESTNAME = "pid_file.test";
+const char* TESTNAME2 = "pid_file.test.2";
 
 class PIDFileTest : public ::testing::Test {
 public:
@@ -63,6 +64,7 @@ private:
     /// @brief Removes any remaining test files
     void removeTestFile() const {
         remove(TESTNAME);
+        remove(TESTNAME2);
     }
 
 };