[PATCH xorg-gtest 04/11] xserver: if the logfile was created by TestStartup, remove it again

Peter Hutterer peter.hutterer at who-t.net
Wed Aug 15 23:36:37 PDT 2012


If the file didn't exist and we created it by checking whether it is
writeable, the file needs to be removed again. Otherwise we have empty
logfiles lying around if the server fails to start.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 src/xserver.cpp | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/xserver.cpp b/src/xserver.cpp
index eb64d3b..0d2ace1 100644
--- a/src/xserver.cpp
+++ b/src/xserver.cpp
@@ -270,6 +270,11 @@ void xorg::testing::XServer::TestStartup(void) {
 
   /* The Xorg server won't start unless the log file and the old log file are
    * writable. */
+  bool logfile_was_present;
+  std::ifstream file_test;
+  file_test.open(log.c_str());
+  logfile_was_present = file_test.good();
+
   std::ofstream log_test;
   log_test.open(log.c_str(), std::ofstream::out);
   log_test.close();
@@ -277,10 +282,13 @@ void xorg::testing::XServer::TestStartup(void) {
     std::string message;
     message += "X.org server log file " + log + " is not writable.";
     throw std::runtime_error(message);
-  }
+  } else if (!logfile_was_present)
+    unlink(log.c_str());
 
   std::string old_log_file = log + ".old";
 
+  file_test.open(old_log_file.c_str());
+  logfile_was_present = file_test.good();
 
   log_test.open(old_log_file.c_str(), std::ofstream::out);
   log_test.close();
@@ -288,8 +296,8 @@ void xorg::testing::XServer::TestStartup(void) {
     std::string message;
     message += "X.org old server log file " + old_log_file + " is not writable.";
     throw std::runtime_error(message);
-  }
-
+  } else if (!logfile_was_present)
+    unlink(old_log_file.c_str());
 }
 
 const std::string& xorg::testing::XServer::GetVersion(void) {
-- 
1.7.11.2



More information about the xorg-devel mailing list