Simple unlink() call to the logfile in use. The log file is only removed if
the server was started and terminated or finished successfully. If it was
never started or the startup failed for some reason, this function does
nothing. Behaviour can be overridden by forcing the removal.

Signed-off-by: Peter Hutterer <[email protected]>
---
Changes to v1:
- add force parameter, update for new state

 include/xorg/gtest/xorg-gtest-xserver.h | 12 ++++++++++++
 src/xserver.cpp                         |  6 ++++++
 2 files changed, 18 insertions(+)

diff --git a/include/xorg/gtest/xorg-gtest-xserver.h 
b/include/xorg/gtest/xorg-gtest-xserver.h
index f3bda9b..2e7ef13 100644
--- a/include/xorg/gtest/xorg-gtest-xserver.h
+++ b/include/xorg/gtest/xorg-gtest-xserver.h
@@ -95,6 +95,18 @@ class XServer : public xorg::testing::Process {
     virtual bool Kill(unsigned int timeout = 0);
 
     /**
+     * Remove the log file used by this server. By default, this function
+     * only removes the log file if the server was terminated or finished
+     * with an exit code of 0.
+     *
+     * If force is true, the log file is removed regardless of the state of
+     * the server.
+     *
+     * @param force Force removal of the log file
+     */
+    void RemoveLogFile(bool force = false);
+
+    /**
      * Waits until this server is ready to take connections.
      */
     void WaitForConnections(void);
diff --git a/src/xserver.cpp b/src/xserver.cpp
index 8647443..ab17e20 100644
--- a/src/xserver.cpp
+++ b/src/xserver.cpp
@@ -371,6 +371,12 @@ bool xorg::testing::XServer::Kill(unsigned int timeout) {
     return true;
 }
 
+void xorg::testing::XServer::RemoveLogFile(bool force) {
+  enum Process::State state = GetState();
+  if (force || state == Process::TERMINATED || state == 
Process::FINISHED_SUCCESS)
+    unlink(d_->options["-logfile"].c_str());
+}
+
 void xorg::testing::XServer::SetOption(const std::string &key, const 
std::string &value) {
   d_->options[key] = value;
 }
-- 
1.7.11.2

_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

Reply via email to