From 48888c80f05ee307c331ba888dd00e783366484d Mon Sep 17 00:00:00 2001 From: Marcin Siodelski Date: Wed, 28 Jan 2015 20:23:21 +0100 Subject: [PATCH] [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. --- src/lib/util/pid_file.cc | 9 +++++---- src/lib/util/tests/pid_file_unittest.cc | 6 ++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/lib/util/pid_file.cc b/src/lib/util/pid_file.cc index 3bc8e0c7fa..05a860d441 100644 --- a/src/lib/util/pid_file.cc +++ b/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 diff --git a/src/lib/util/tests/pid_file_unittest.cc b/src/lib/util/tests/pid_file_unittest.cc index d883c16e96..faaa195194 100644 --- a/src/lib/util/tests/pid_file_unittest.cc +++ b/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); } }; -- 2.47.3