[Libreoffice-commits] online.git: loolwsd/LOOLWSD.cpp loolwsd/LOOLWSD.hpp

Henry Castro hcastro at collabora.com
Wed Nov 25 18:50:22 PST 2015


 loolwsd/LOOLWSD.cpp |    9 ++++++---
 loolwsd/LOOLWSD.hpp |    1 +
 2 files changed, 7 insertions(+), 3 deletions(-)

New commits:
commit 964d95f04b279233c01cc06d8dbab71af6013e15
Author: Henry Castro <hcastro at collabora.com>
Date:   Wed Nov 25 22:49:34 2015 -0400

    loolwsd: handle a graceful shutdown

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 7ee8694..1b1706c 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -429,7 +429,8 @@ public:
                         }
                     }
                 }
-                while (!pollTimeout || (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE));
+                while (!LOOLWSD::isShutDown &&
+                        (!pollTimeout || (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE)));
 
                 queue.clear();
                 queue.put("eof");
@@ -585,6 +586,7 @@ Poco::SharedMemory LOOLWSD::_sharedForkChild("loolwsd", sizeof(bool), Poco::Shar
 
 int LOOLWSD::_numPreSpawnedChildren = 10;
 bool LOOLWSD::doTest = false;
+volatile bool LOOLWSD::isShutDown = false;
 #if ENABLE_DEBUG
 bool LOOLWSD::runningAsRoot = false;
 int LOOLWSD::uid = 0;
@@ -605,6 +607,7 @@ LOOLWSD::~LOOLWSD()
 void LOOLWSD::handleSignal(int aSignal)
 {
     std::cout << Util::logPrefix() << "Signal received: " << strsignal(aSignal) << std::endl;
+    LOOLWSD::isShutDown = true;
 }
 
 void LOOLWSD::setSignals(bool isIgnored)
@@ -1145,7 +1148,7 @@ void LOOLWSD::desktopMain()
         else if (pid < 0)
             std::cout << Util::logPrefix() << "Child error: " << strerror(errno);
 
-        if ( _sharedForkChild.begin()[0] > 0 )
+        if (!LOOLWSD::isShutDown && _sharedForkChild.begin()[0] > 0 )
         {
             _namedMutexLOOL.lock();
             _sharedForkChild.begin()[0] = _sharedForkChild.begin()[0] - 1;
@@ -1287,7 +1290,7 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
         waitForTerminationRequest();
     }
 
-    while (!LOOLWSD::doTest && MasterProcessSession::_childProcesses.size() > 0)
+    while (!LOOLWSD::isShutDown && !LOOLWSD::doTest && MasterProcessSession::_childProcesses.size() > 0)
     {
         int status;
         pid_t pid = waitpid(-1, &status, WUNTRACED | WNOHANG);
diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp
index 2e63038..342b36c 100644
--- a/loolwsd/LOOLWSD.hpp
+++ b/loolwsd/LOOLWSD.hpp
@@ -33,6 +33,7 @@ public:
     static int portNumber;
     static int timeoutCounter;
     static bool doTest;
+    static bool volatile isShutDown;
     static std::string cache;
     static std::string sysTemplate;
     static std::string loTemplate;


More information about the Libreoffice-commits mailing list