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

2016-04-05 Thread Michael Meeks
 loolwsd/LOOLBroker.cpp |2 +-
 loolwsd/LOOLWSD.cpp|   28 ++--
 2 files changed, 15 insertions(+), 15 deletions(-)

New commits:
commit d498bff3f074ca629e56211e1247cfeb2cb269e5
Author: Michael Meeks 
Date:   Tue Apr 5 12:23:02 2016 +0100

Plural of child is children.

diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp
index 6dae2bd..ea75130 100644
--- a/loolwsd/LOOLBroker.cpp
+++ b/loolwsd/LOOLBroker.cpp
@@ -1159,7 +1159,7 @@ private:
 if (tokens[0] == "spawn" && tokens.count() == 2)
 {
 const auto count = std::stoi(tokens[1]);
-Log::info("Spawning " + tokens[1] + " childs per request.");
+Log::info("Spawning " + tokens[1] + " children on request.");
 ForkCounter = count;
 }
 }
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 9b91c85..194cad3 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -173,15 +173,15 @@ using Poco::XML::NodeList;
 
 /// New LOK child processes ready to host documents.
 //TODO: Move to a more sensible namespace.
-static std::vector newChilds;
-static std::mutex newChildsMutex;
-static std::condition_variable newChildsCV;
+static std::vector newChildren;
+static std::mutex newChildrenMutex;
+static std::condition_variable newChildrenCV;
 static std::map docBrokers;
 static std::mutex docBrokersMutex;
 
 void forkChildren(int number)
 {
-assert(!newChildsMutex.try_lock()); // check it is held.
+assert(!newChildrenMutex.try_lock()); // check it is held.
 
 const std::string aMessage = "spawn " + std::to_string(number) + "\n";
 Log::debug("MasterToBroker: " + aMessage.substr(0, aMessage.length() - 1));
@@ -190,15 +190,15 @@ void forkChildren(int number)
 
 void preForkChildren()
 {
-std::unique_lock lock(newChildsMutex);
+std::unique_lock lock(newChildrenMutex);
 forkChildren(LOOLWSD::NumPreSpawnedChildren);
 }
 
 std::shared_ptr getNewChild()
 {
-std::unique_lock lock(newChildsMutex);
+std::unique_lock lock(newChildrenMutex);
 
-const int available = newChilds.size();
+const int available = newChildren.size();
 int balance = LOOLWSD::NumPreSpawnedChildren;
 if (available == 0)
 {
@@ -213,10 +213,10 @@ std::shared_ptr getNewChild()
 forkChildren(balance);
 
 const auto timeout = std::chrono::milliseconds(CHILD_TIMEOUT_SECS * 1000);
-if (newChildsCV.wait_for(lock, timeout, [](){ return !newChilds.empty(); 
}))
+if (newChildrenCV.wait_for(lock, timeout, [](){ return 
!newChildren.empty(); }))
 {
-auto child = newChilds.back();
-newChilds.pop_back();
+auto child = newChildren.back();
+newChildren.pop_back();
 return child;
 }
 
@@ -681,10 +681,10 @@ public:
 
 Log::info("New child [" + std::to_string(pid) + "].");
 auto ws = std::make_shared(request, response);
-std::unique_lock lock(newChildsMutex);
-newChilds.emplace_back(std::make_shared(pid, ws));
-Log::info("Have " + std::to_string(newChilds.size()) + " childs.");
-newChildsCV.notify_one();
+std::unique_lock lock(newChildrenMutex);
+newChildren.emplace_back(std::make_shared(pid, ws));
+Log::info("Have " + std::to_string(newChildren.size()) + " 
children.");
+newChildrenCV.notify_one();
 return;
 }
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-04-05 Thread Michael Meeks
 loolwsd/LOOLBroker.cpp |   19 +++
 loolwsd/LOOLWSD.cpp|   24 ++--
 2 files changed, 21 insertions(+), 22 deletions(-)

New commits:
commit 0278743fb271acd1f6fadc5f214a1dcf85e5bf4b
Author: Michael Meeks 
Date:   Mon Apr 4 15:17:03 2016 +0100

Move pre-forking of children from loolbroker to WSD.

diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp
index ca96cba..6dae2bd 100644
--- a/loolwsd/LOOLBroker.cpp
+++ b/loolwsd/LOOLBroker.cpp
@@ -59,9 +59,8 @@ static const std::string BROKER_PREFIX = "lokit";
 static int WriterNotify = -1;
 static int ReaderBroker = -1;
 
-static std::atomic ForkCounter;
+static std::atomic ForkCounter( 0 );
 static unsigned int ChildCounter = 0;
-static int NumPreSpawnedChildren = 1;
 
 using namespace LOOLProtocol;
 
@@ -1278,9 +1277,6 @@ static void printArgumentHelp()
 std::cout << "  --lotemplate=   path of libreoffice template to 
pre-populate chroot with." << std::endl;
 std::cout << "  --pipe= path of loolwsd pipe to connect 
to on startup." << std::endl;
 std::cout << "  --losubpath=path to libreoffice install" << 
std::endl;
-std::cout << "" << std::endl;
-std::cout << "  Some paramaters are optional:" << std::endl;
-std::cout << "  --numprespawns=   pre-fork at least  
processes [1]" << std::endl;
 }
 
 void setupPipes(const std::string )
@@ -1348,11 +1344,6 @@ int main(int argc, char** argv)
 eq = std::strchr(cmd, '=');
 childRoot = std::string(eq+1);
 }
-else if (std::strstr(cmd, "--numprespawns=") == cmd)
-{
-eq = std::strchr(cmd, '=');
-NumPreSpawnedChildren = std::stoi(std::string(eq+1));
-}
 else if (std::strstr(cmd, "--clientport=") == cmd)
 {
 eq = std::strchr(cmd, '=');
@@ -1361,8 +1352,7 @@ int main(int argc, char** argv)
 }
 
 if (loSubPath.empty() || sysTemplate.empty() ||
-loTemplate.empty() || childRoot.empty() ||
-NumPreSpawnedChildren < 1)
+loTemplate.empty() || childRoot.empty())
 {
 printArgumentHelp();
 return 1;
@@ -1381,16 +1371,13 @@ int main(int argc, char** argv)
 
 Log::info("Preinit stage OK.");
 
-// We must have at least one child, more is created dynamically.
+// We must have at least one child, more are created dynamically.
 if (createLibreOfficeKit(childRoot, sysTemplate, loTemplate, loSubPath) < 
0)
 {
 Log::error("Error: failed to create children.");
 std::exit(Application::EXIT_SOFTWARE);
 }
 
-if (NumPreSpawnedChildren > 1)
-ForkCounter = NumPreSpawnedChildren - 1;
-
 ChildDispatcher childDispatcher;
 Log::info("loolbroker is ready.");
 
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 93e65ee..9b91c85 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -179,6 +179,21 @@ static std::condition_variable newChildsCV;
 static std::map docBrokers;
 static std::mutex docBrokersMutex;
 
+void forkChildren(int number)
+{
+assert(!newChildsMutex.try_lock()); // check it is held.
+
+const std::string aMessage = "spawn " + std::to_string(number) + "\n";
+Log::debug("MasterToBroker: " + aMessage.substr(0, aMessage.length() - 1));
+IoUtil::writeFIFO(LOOLWSD::BrokerWritePipe, aMessage);
+}
+
+void preForkChildren()
+{
+std::unique_lock lock(newChildsMutex);
+forkChildren(LOOLWSD::NumPreSpawnedChildren);
+}
+
 std::shared_ptr getNewChild()
 {
 std::unique_lock lock(newChildsMutex);
@@ -195,11 +210,7 @@ std::shared_ptr getNewChild()
 }
 
 if (balance > 0)
-{
-const std::string aMessage = "spawn " + std::to_string(balance) + "\n";
-Log::debug("MasterToBroker: " + aMessage.substr(0, aMessage.length() - 
1));
-IoUtil::writeFIFO(LOOLWSD::BrokerWritePipe, aMessage);
-}
+forkChildren(balance);
 
 const auto timeout = std::chrono::milliseconds(CHILD_TIMEOUT_SECS * 1000);
 if (newChildsCV.wait_for(lock, timeout, [](){ return !newChilds.empty(); 
}))
@@ -1149,7 +1160,6 @@ Process::PID LOOLWSD::createBroker()
 args.push_back("--systemplate=" + SysTemplate);
 args.push_back("--lotemplate=" + LoTemplate);
 args.push_back("--childroot=" + ChildRoot);
-args.push_back("--numprespawns=" + std::to_string(NumPreSpawnedChildren));
 args.push_back("--clientport=" + std::to_string(ClientPortNumber));
 
 const std::string brokerPath = 
Path(Application::instance().commandPath()).parent().toString() + "loolbroker";
@@ -1316,6 +1326,8 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 waitForTerminationRequest();
 }
 
+preForkChildren();
+
 time_t last30SecCheck = time(NULL);
 time_t lastFiveMinuteCheck = time(NULL);
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org

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

2016-04-03 Thread Ashod Nakashian
 loolwsd/LOOLBroker.cpp |6 ++
 loolwsd/LOOLWSD.cpp|   31 +++
 2 files changed, 37 insertions(+)

New commits:
commit f4b80e630a0dce207bab9d993353a9243e3511b3
Author: Ashod Nakashian 
Date:   Sun Apr 3 19:00:37 2016 -0400

loolwsd: consume new child from wsd

And spawn new child instances.

Change-Id: I51886f4645a1c8944ccde2e0fae415afc7c8fc24
Reviewed-on: https://gerrit.libreoffice.org/23788
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp
index a529316..5231eab 100644
--- a/loolwsd/LOOLBroker.cpp
+++ b/loolwsd/LOOLBroker.cpp
@@ -268,6 +268,12 @@ private:
 Process::PID nPid = 
static_cast(std::stoi(tokens[1]));
 removeChild(nPid, true);
 }
+else if (tokens[0] == "spawn" && tokens.count() == 2)
+{
+const auto count = std::stoi(tokens[1]);
+Log::info("Spawning " + tokens[1] + " childs per request.");
+ForkCounter = count;
+}
 }
 
 private:
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index f4224be..ded9089 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -183,6 +183,8 @@ public:
 {
 }
 
+/// pid is the process ID of the child.
+/// ws is the control WebSocket to the child.
 ChildProcess(const Poco::Process::PID pid, const 
std::shared_ptr& ws) :
 _pid(pid),
 _ws(ws)
@@ -247,6 +249,35 @@ static std::mutex newChildsMutex;
 static std::map docBrokers;
 static std::mutex docBrokersMutex;
 
+std::shared_ptr getNewChild()
+{
+std::unique_lock lock(newChildsMutex);
+
+const signed available = newChilds.size();
+signed balance = LOOLWSD::NumPreSpawnedChildren;
+if (available == 0)
+{
+Log::error("No available child. Sending spawn request to Broker and 
failing.");
+}
+else
+{
+balance -= available - 1;
+}
+
+const std::string aMessage = "spawn " + std::to_string(balance) + "\n";
+Log::debug("MasterToBroker: " + aMessage.substr(0, aMessage.length() - 1));
+IoUtil::writeFIFO(LOOLWSD::BrokerWritePipe, aMessage);
+
+if (available > 0)
+{
+auto child = newChilds.back();
+newChilds.pop_back();
+return child;
+}
+
+return nullptr;
+}
+
 /// Handles the filename part of the convert-to POST request payload.
 class ConvertToPartHandler : public PartHandler
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-03-01 Thread Tor Lillqvist
 loolwsd/LOOLBroker.cpp |2 +-
 loolwsd/LOOLWSD.cpp|1 -
 2 files changed, 1 insertion(+), 2 deletions(-)

New commits:
commit 73282c50d6c39b7b5788bee4c2a0bc01a3887793
Author: Tor Lillqvist 
Date:   Wed Mar 2 08:26:15 2016 +0200

Make preinit the default. Turn off with LOK_NO_PREINIT

diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp
index 0ac53c8..ddeb815 100644
--- a/loolwsd/LOOLBroker.cpp
+++ b/loolwsd/LOOLBroker.cpp
@@ -775,7 +775,7 @@ int main(int argc, char** argv)
 }
 
 // Initialize LoKit and hope we can fork and save memory by sharing pages.
-const bool sharePages = std::getenv("LOK_PREINIT") != nullptr
+const bool sharePages = std::getenv("LOK_NO_PREINIT") == nullptr
   ? globalPreinit(loTemplate)
   : std::getenv("LOK_FORK") != nullptr;
 
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 69a3774..c5d3cc3 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -911,7 +911,6 @@ int LOOLWSD::main(const std::vector& /*args*/)
 return Application::EXIT_USAGE;
 }
 
-//Environment::set("LOK_PREINIT", "1");
 //Environment::set("LOK_FORK", "1");
 //Environment::set("LD_BIND_NOW", "1");
 //Environment::set("LOK_VIEW_CALLBACK", "1");
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-02-16 Thread Henry Castro
 loolwsd/LOOLBroker.cpp |2 +-
 loolwsd/LOOLWSD.cpp|2 +-
 loolwsd/Util.cpp   |   12 
 loolwsd/Util.hpp   |3 +++
 4 files changed, 17 insertions(+), 2 deletions(-)

New commits:
commit a607159a8aa40ca6de4243ce19685b35233f69f2
Author: Henry Castro 
Date:   Tue Feb 16 17:25:51 2016 -0400

loolwsd: catch exception requestTermination

diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp
index b29b4a9..9561be9 100644
--- a/loolwsd/LOOLBroker.cpp
+++ b/loolwsd/LOOLBroker.cpp
@@ -912,7 +912,7 @@ int main(int argc, char** argv)
 for (auto& it : _childProcesses)
 {
 Log::info("Requesting child process " + std::to_string(it.first) + " 
to terminate.");
-Process::requestTermination(it.first);
+Util::requestTermination(it.first);
 }
 
 // Wait and kill child processes
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 8d4cff1..b7cb356 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -1088,7 +1088,7 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 // Terminate child processes
 Util::writeFIFO(LOOLWSD::BrokerWritePipe, "eof\r\n");
 Log::info("Requesting child process " + std::to_string(pidBroker) + " to 
terminate");
-Process::requestTermination(pidBroker);
+Util::requestTermination(pidBroker);
 
 // wait broker process finish
 waitpid(pidBroker, , WUNTRACED);
diff --git a/loolwsd/Util.cpp b/loolwsd/Util.cpp
index 1685d38..697c1b5 100644
--- a/loolwsd/Util.cpp
+++ b/loolwsd/Util.cpp
@@ -543,6 +543,18 @@ namespace Util
 
 return nRetVal;
 }
+
+void requestTermination(const Poco::Process::PID& aPID)
+{
+try
+{
+Poco::Process::requestTermination(aPID);
+}
+catch(const Poco::Exception& exc)
+{
+Log::warn("Exception: " + exc.message());
+}
+}
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/loolwsd/Util.hpp b/loolwsd/Util.hpp
index b6f6f08..4a72945 100644
--- a/loolwsd/Util.hpp
+++ b/loolwsd/Util.hpp
@@ -17,6 +17,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -119,6 +120,8 @@ namespace Util
 
 int getChildStatus(const int nCode);
 int getSignalStatus(const int nCode);
+
+void requestTermination(const Poco::Process::PID& aPID);
 };
 
 //TODO: Move to own file.
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-02-16 Thread Henry Castro
 loolwsd/LOOLBroker.cpp |4 ++--
 loolwsd/LOOLWSD.cpp|2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

New commits:
commit 9b4099c41cd11d8cd05e90e4aa8c45c37a83207f
Author: Henry Castro 
Date:   Tue Feb 16 17:11:33 2016 -0400

loolwsd: check if the named pipes exists

diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp
index 0b41fee..b29b4a9 100644
--- a/loolwsd/LOOLBroker.cpp
+++ b/loolwsd/LOOLBroker.cpp
@@ -491,7 +491,7 @@ static int createLibreOfficeKit(const bool sharePages,
 const Path pipePath = Path::forDirectory(childRoot + Path::separator() + 
FIFO_PATH);
 const std::string pipeKit = Path(pipePath, BROKER_PREFIX + 
std::to_string(childCounter++) + BROKER_SUFIX).toString();
 
-if (mkfifo(pipeKit.c_str(), 0666) < 0)
+if (mkfifo(pipeKit.c_str(), 0666) < 0 && errno != EEXIST)
 {
 Log::error("Error: Failed to create pipe FIFO [" + pipeKit + "].");
 return -1;
@@ -750,7 +750,7 @@ int main(int argc, char** argv)
 
 int nFlags = O_RDONLY | O_NONBLOCK;
 const std::string pipeBroker = Path(pipePath, FIFO_BROKER).toString();
-if (mkfifo(pipeBroker.c_str(), 0666) == -1)
+if (mkfifo(pipeBroker.c_str(), 0666) < 0 && errno != EEXIST)
 {
 Log::error("Error: Failed to create pipe FIFO [" + FIFO_BROKER + "].");
 exit(Application::EXIT_SOFTWARE);
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index ef37ab5..8d4cff1 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -941,7 +941,7 @@ int LOOLWSD::main(const std::vector& /*args*/)
 }
 
 const std::string pipeLoolwsd = Path(pipePath, FIFO_LOOLWSD).toString();
-if (mkfifo(pipeLoolwsd.c_str(), 0666) == -1)
+if (mkfifo(pipeLoolwsd.c_str(), 0666) < 0 && errno != EEXIST)
 {
 Log::error("Error: Failed to create pipe FIFO [" + pipeLoolwsd + "].");
 return Application::EXIT_SOFTWARE;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-02-15 Thread Ashod Nakashian
 loolwsd/LOOLBroker.cpp |4 +++-
 loolwsd/LOOLWSD.cpp|4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)

New commits:
commit 90776a3c0df4e05749ae1dec79b16d2c6a0cd888
Author: Ashod Nakashian 
Date:   Mon Feb 15 18:16:02 2016 -0500

loolwsd: control preinit vs fork using envars and disable bind-now

Change-Id: I63dffa18da69751ab72463bb64065d235d811db5
Reviewed-on: https://gerrit.libreoffice.org/22381
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp
index 22ae676..9e9089e 100644
--- a/loolwsd/LOOLBroker.cpp
+++ b/loolwsd/LOOLBroker.cpp
@@ -765,7 +765,9 @@ int main(int argc, char** argv)
 }
 
 // Initialize LoKit and hope we can fork and save memory by sharing pages.
-const bool sharePages = globalPreinit(loTemplate);
+const bool sharePages = std::getenv("LOK_PREINIT") != nullptr
+  ? globalPreinit(loTemplate)
+  : std::getenv("LOK_FORK") != nullptr;
 
 if (!sharePages)
 Log::warn("Cannot fork, will spawn instead.");
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index f2d41b7..1f1480e 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -885,7 +885,9 @@ int LOOLWSD::main(const std::vector& /*args*/)
 {
 Log::initialize("wsd");
 
-Poco::Environment::set("LD_BIND_NOW", "1");
+//Poco::Environment::set("LOK_PREINIT", "1");
+//Poco::Environment::set("LOK_FORK", "1");
+//Poco::Environment::set("LD_BIND_NOW", "1");
 //Poco::Environment::set("LOK_VIEW_CALLBACK", "1");
 
 #ifdef __linux
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-02-03 Thread Henry Castro
 loolwsd/LOOLBroker.cpp |8 
 loolwsd/LOOLWSD.cpp|8 
 2 files changed, 16 insertions(+)

New commits:
commit 661ae622599e450152d298eb9b114a9ad0dc9175
Author: Henry Castro 
Date:   Wed Feb 3 17:43:04 2016 -0400

loolwsd: exit when error no child process

diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp
index 6c3b3f8..a9af6cd 100644
--- a/loolwsd/LOOLBroker.cpp
+++ b/loolwsd/LOOLBroker.cpp
@@ -994,7 +994,15 @@ int main(int argc, char** argv)
 pipeHandler.syncChilds();
 }
 else if (pid < 0)
+{
 Log::error("Error: waitpid failed.");
+// No child processes
+if (errno == ECHILD)
+{
+TerminationFlag = true;
+continue;
+}
+}
 
 if (forkCounter > 0)
 {
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 35b8cff..f382758 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -1049,7 +1049,15 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 }
 }
 else if (pid < 0)
+{
 Log::error("Error: waitpid failed.");
+// No child processes
+if (errno == ECHILD)
+{
+TerminationFlag = true;
+continue;
+}
+}
 
 if (timeoutCounter++ == INTERVAL_PROBES)
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-02-03 Thread Henry Castro
 loolwsd/LOOLBroker.cpp |6 --
 loolwsd/LOOLWSD.cpp|6 --
 loolwsd/Util.cpp   |2 ++
 3 files changed, 10 insertions(+), 4 deletions(-)

New commits:
commit 70ff592624f69c9c3804022bd6cb527f3b8022c3
Author: Henry Castro 
Date:   Wed Feb 3 18:08:16 2016 -0400

loolwsd: use strsignal

diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp
index a9af6cd..5776ab9 100644
--- a/loolwsd/LOOLBroker.cpp
+++ b/loolwsd/LOOLBroker.cpp
@@ -970,7 +970,8 @@ int main(int argc, char** argv)
 #endif
 Log::error() << "Child process [" << pid << "] " << fate
  << " with " << Util::signalName(WTERMSIG(status))
- << " signal. " << Log::end;
+ << " signal: " << strsignal(WTERMSIG(status))
+ << Log::end;
 
 removeChild(pid);
 }
@@ -978,7 +979,8 @@ int main(int argc, char** argv)
 {
 Log::info() << "Child process [" << pid << "] stopped with "
 << Util::signalName(WSTOPSIG(status))
-<< " signal. " << Log::end;
+<< " signal: " << strsignal(WTERMSIG(status))
+<< Log::end;
 }
 else if (WIFCONTINUED(status))
 {
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index f382758..eeb3d2d 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -1022,7 +1022,8 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 #endif
 Log::error() << "Child process [" << pid << "] " << fate
  << " with " << 
Util::signalName(WTERMSIG(status))
- << " signal. " << Log::end;
+ << " signal: " << strsignal(WTERMSIG(status))
+ << Log::end;
 
 break;
 }
@@ -1030,7 +1031,8 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 {
 Log::info() << "Child process [" << pid << "] stopped with 
"
 << Util::signalName(WSTOPSIG(status))
-<< " signal. " << Log::end;
+<< " signal: " << strsignal(WTERMSIG(status))
+<< Log::end;
 }
 else if (WIFCONTINUED(status))
 {
diff --git a/loolwsd/Util.cpp b/loolwsd/Util.cpp
index a764ff4..e4ae391 100644
--- a/loolwsd/Util.cpp
+++ b/loolwsd/Util.cpp
@@ -427,6 +427,7 @@ namespace Util
 TerminationState = ( aSignal == SIGTERM ? LOOLState::LOOL_ABNORMAL 
: LOOLState::LOOL_STOPPING );
 
 Log::info() << "Termination signal received: "
+<< Util::signalName(aSignal) << " "
 << strsignal(aSignal) << Log::end;
 }
 }
@@ -451,6 +452,7 @@ namespace Util
 void handleFatalSignal(const int aSignal)
 {
 Log::error() << "Fatal signal received: "
+ << Util::signalName(aSignal) << " "
  << strsignal(aSignal) << Log::end;
 
 if (getenv("LOOL_DEBUG"))
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-02-03 Thread Henry Castro
 loolwsd/LOOLBroker.cpp |2 +-
 loolwsd/LOOLWSD.cpp|4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

New commits:
commit 5848cff63409f6d708d562e2c702425f65647d7a
Author: Henry Castro 
Date:   Wed Feb 3 19:51:27 2016 -0400

loolwsd: wait for loolbroker process to change state

diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp
index 858009f..41305d6 100644
--- a/loolwsd/LOOLBroker.cpp
+++ b/loolwsd/LOOLBroker.cpp
@@ -965,7 +965,7 @@ int main(int argc, char** argv)
 else
 if (WIFSIGNALED(status))
 {
-nChildExitCode = Util::getSignalStatus(WEXITSTATUS(status));
+nChildExitCode = Util::getSignalStatus(WTERMSIG(status));
 std::string fate = "died";
 #ifdef WCOREDUMP
 if (WCOREDUMP(status))
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index eeb3d2d..02482d9 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -1000,7 +1000,7 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 unsigned timeoutCounter = 0;
 while (!TerminationFlag && !LOOLWSD::DoTest)
 {
-const pid_t pid = waitpid(-1, , WUNTRACED | WNOHANG);
+const pid_t pid = waitpid(pidBroker, , WUNTRACED | WNOHANG);
 if (pid > 0)
 {
 if (pidBroker == pid)
@@ -1084,7 +1084,7 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 Process::requestTermination(pidBroker);
 
 // wait broker process finish
-waitpid(-1, , WUNTRACED);
+waitpid(pidBroker, , WUNTRACED);
 
 close(BrokerWritePipe);
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-02-01 Thread Ashod Nakashian
 loolwsd/LOOLBroker.cpp |1 +
 loolwsd/LOOLWSD.cpp|   10 ++
 2 files changed, 7 insertions(+), 4 deletions(-)

New commits:
commit f3b319ee7f847d21472e6914b189ed8d509efd81
Author: Ashod Nakashian 
Date:   Mon Feb 1 20:47:40 2016 -0500

loolwsd: each HTTPServer has its params and skip failed child query

Change-Id: I41c730a935fd0d2e1e3181cced529d414c3aebb0
Reviewed-on: https://gerrit.libreoffice.org/22014
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp
index cb93536..24e8d94 100644
--- a/loolwsd/LOOLBroker.cpp
+++ b/loolwsd/LOOLBroker.cpp
@@ -379,6 +379,7 @@ public:
 }
 
 log << Log::end;
+++it;
 continue;
 }
 
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 2e59e0e..e13438e 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -963,20 +963,22 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 // We must have sufficient available threads
 // in the default ThreadPool to dispatch
 // connections, otherwise we will deadlock.
-auto params = new HTTPServerParams();
-params->setMaxThreads(MAX_SESSIONS);
+auto params1 = new HTTPServerParams();
+params1->setMaxThreads(MAX_SESSIONS);
+auto params2 = new HTTPServerParams();
+params2->setMaxThreads(MAX_SESSIONS);
 
 // Start a server listening on the port for clients
 ServerSocket svs(ClientPortNumber);
 ThreadPool threadPool(NumPreSpawnedChildren*6, MAX_SESSIONS * 2);
-HTTPServer srv(new RequestHandlerFactory(), 
threadPool, svs, params);
+HTTPServer srv(new RequestHandlerFactory(), 
threadPool, svs, params1);
 
 srv.start();
 
 // And one on the port for child processes
 SocketAddress addr2("127.0.0.1", MASTER_PORT_NUMBER);
 ServerSocket svs2(addr2);
-HTTPServer srv2(new RequestHandlerFactory(), 
threadPool, svs2, params);
+HTTPServer srv2(new RequestHandlerFactory(), 
threadPool, svs2, params2);
 
 srv2.start();
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-01-26 Thread Henry Castro
 loolwsd/LOOLBroker.cpp |3 +++
 loolwsd/LOOLWSD.cpp|2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)

New commits:
commit faf2a57d19b0897eeb985f1b431d901b6cdf8f94
Author: Henry Castro 
Date:   Tue Jan 26 21:22:07 2016 -0400

loolwsd: eof broker pipe

diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp
index 2bef170..78c4fe6 100644
--- a/loolwsd/LOOLBroker.cpp
+++ b/loolwsd/LOOLBroker.cpp
@@ -472,6 +472,9 @@ public:
 pStart++;
 
 Log::trace("BrokerFromMaster: " + aMessage);
+if (aMessage == "eof")
+break;
+
 const auto duration = (std::chrono::steady_clock::now() - 
lastMaintenanceTime);
 if (duration >= std::chrono::seconds(10))
 {
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 10ddeeb..ed555e8 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -1072,7 +1072,7 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 threadPool2.joinAll();
 
 // Terminate child processes
-Util::writeFIFO(LOOLWSD::BrokerWritePipe, "eof");
+Util::writeFIFO(LOOLWSD::BrokerWritePipe, "eof\r\n");
 Log::info("Requesting child process " + std::to_string(pidBroker) + " to 
terminate");
 Process::requestTermination(pidBroker);
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-01-04 Thread Ashod Nakashian
 loolwsd/LOOLBroker.cpp   |9 +
 loolwsd/LOOLWSD.cpp  |5 +++--
 loolwsd/MasterProcessSession.cpp |   25 +++--
 loolwsd/MasterProcessSession.hpp |7 ---
 4 files changed, 27 insertions(+), 19 deletions(-)

New commits:
commit 75c65af9306dfdcca2897e9cec5365f8c9c0e230
Author: Ashod Nakashian 
Date:   Sun Jan 3 14:52:32 2016 -0500

loolwsd: childId is now string

Change-Id: I7037c03d2b40ff88deed0619e8a34ce5434913a3
Reviewed-on: https://gerrit.libreoffice.org/21095
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp
index 169e725..75a3395 100644
--- a/loolwsd/LOOLBroker.cpp
+++ b/loolwsd/LOOLBroker.cpp
@@ -655,7 +655,8 @@ int main(int argc, char** argv)
 exit(-1);
 }
 
-const std::string childId = std::to_string(Util::rng::getNext());
+//TODO: Why not use our PID?
+const std::string childId = Util::encodeId(Util::rng::getNext());
 
 const Path jailPath = Path::forDirectory(childRoot + Path::separator() + 
childId);
 Log::info("Jail path: " + jailPath.toString());
@@ -674,10 +675,10 @@ int main(int argc, char** argv)
 File(loolkitPath).copyTo(Path(jailPath, JAILED_LOOLKIT_PATH).toString());
 
 // We need this because sometimes the hostname is not resolved
-std::vector networkFiles = {"/etc/host.conf", "/etc/hosts", 
"/etc/nsswitch.conf", "/etc/resolv.conf"};
-for (std::vector::iterator it = networkFiles.begin(); it != 
networkFiles.end(); ++it)
+const std::vector networkFiles = {"/etc/host.conf", 
"/etc/hosts", "/etc/nsswitch.conf", "/etc/resolv.conf"};
+for (const auto& filename : networkFiles)
 {
-   File networkFile(*it);
+   const File networkFile(filename);
if (networkFile.exists())
{
networkFile.copyTo(Path(jailPath, "/etc").toString());
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index f21bfd4..e41ec2a 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -310,8 +310,9 @@ public:
 Poco::Net::HTMLForm form(request, request.stream(), handler);
 if (form.has("childid") && form.has("name"))
 {
-std::string dirPath = LOOLWSD::childRoot + 
Path::separator() + form.get("childid") + LOOLSession::jailDocumentURL +
-Path::separator() + "insertfile";
+const std::string dirPath = LOOLWSD::childRoot + 
Path::separator() + form.get("childid")
+  + LOOLSession::jailDocumentURL
+  + Path::separator() + 
"insertfile";
 File(dirPath).createDirectory();
 std::string fileName = dirPath + Path::separator() + 
form.get("name");
 File(tmpPath).moveTo(fileName);
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index 2d5478d..dd66fc2 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -52,7 +52,6 @@ MasterProcessSession::MasterProcessSession(const std::string& 
id,
const Kind kind,

std::shared_ptr ws) :
 LOOLSession(id, kind, ws),
-_childId(0),
 _pidChild(0),
 _curPart(0),
 _loadPart(-1)
@@ -212,7 +211,7 @@ bool MasterProcessSession::_handleInput(const char *buffer, 
int length)
 return false;
 }
 
-const UInt64 childId = std::stoull(tokens[1]);
+const auto childId = tokens[1];
 setId(tokens[2]);
 const Process::PID pidChild = std::stoull(tokens[3]);
 
@@ -336,12 +335,12 @@ bool MasterProcessSession::_handleInput(const char 
*buffer, int length)
 
 bool MasterProcessSession::haveSeparateProcess()
 {
-return _childId != 0;
+return !_childId.empty();
 }
 
-Path MasterProcessSession::getJailPath(UInt64 childId)
+Poco::Path MasterProcessSession::getJailPath(const std::string& childId)
 {
-return Path::forDirectory(LOOLWSD::childRoot + Path::separator() + 
std::to_string(childId));
+return Path::forDirectory(LOOLWSD::childRoot + Path::separator() + 
childId);
 }
 
 bool MasterProcessSession::invalidateTiles(const char* /*buffer*/, int 
/*length*/, StringTokenizer& tokens)
@@ -384,7 +383,7 @@ bool MasterProcessSession::loadDocument(const char* 
/*buffer*/, int /*length*/,
 
 // request new URL session
 const std::string aMessage = "request " + getId() + " " + _docURL + 
"\r\n";
-Log::info("Sending to Broker: " + aMessage);
+Log::debug("Sending to Broker: " + aMessage);
 Util::writeFIFO(LOOLWSD::BrokerWritePipe, aMessage.c_str(), 
aMessage.length());
 }
 catch (const Poco::SyntaxException&)
@@ -613,10 +612,16 @@ void MasterProcessSession::dispatchChild()
  

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

2016-01-04 Thread Ashod Nakashian
 loolwsd/LOOLBroker.cpp |2 +-
 loolwsd/LOOLWSD.cpp|   27 ---
 2 files changed, 21 insertions(+), 8 deletions(-)

New commits:
commit 2104712b72c5cb1545acc3ea47d59e40341f0cbd
Author: Ashod Nakashian 
Date:   Mon Jan 4 13:59:50 2016 -0500

loolwsd: exception handling in wsd queue handler

Change-Id: I66f1990a20151c67346922273a98ecc5a91dc58f
Reviewed-on: https://gerrit.libreoffice.org/21096
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp
index 75a3395..2c4c819 100644
--- a/loolwsd/LOOLBroker.cpp
+++ b/loolwsd/LOOLBroker.cpp
@@ -656,7 +656,7 @@ int main(int argc, char** argv)
 }
 
 //TODO: Why not use our PID?
-const std::string childId = Util::encodeId(Util::rng::getNext());
+const std::string childId = std::to_string(Util::rng::getNext());
 
 const Path jailPath = Path::forDirectory(childRoot + Path::separator() + 
childId);
 Log::info("Jail path: " + jailPath.toString());
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index e41ec2a..a9c7756 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -167,20 +167,33 @@ public:
 
 void run() override
 {
-static const std::string thread_name = "wsd_queue_handler";
+static const std::string thread_name = "wsd_queue";
 #ifdef __linux
 if (prctl(PR_SET_NAME, reinterpret_cast(thread_name.c_str()), 0, 0, 0) != 0)
 Log::error("Cannot set thread name to " + thread_name + ".");
 #endif
 Log::debug("Thread [" + thread_name + "] started.");
 
-while (true)
+try
+{
+while (true)
+{
+const std::string input = _queue.get();
+if (input == "eof")
+break;
+if (!_session->handleInput(input.c_str(), input.size()))
+break;
+}
+}
+catch (const std::exception& exc)
+{
+Log::error(std::string("Exception: ") + exc.what());
+raise(SIGABRT);
+}
+catch (...)
 {
-const std::string input = _queue.get();
-if (input == "eof")
-break;
-if (!_session->handleInput(input.c_str(), input.size()))
-break;
+Log::error("Unexpected Exception.");
+raise(SIGABRT);
 }
 
 Log::debug("Thread [" + thread_name + "] finished.");
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2015-12-29 Thread Henry Castro
 loolwsd/LOOLBroker.cpp |   15 ++-
 loolwsd/LOOLWSD.cpp|2 ++
 2 files changed, 12 insertions(+), 5 deletions(-)

New commits:
commit 33a7f6adbb204208f64d95b38a28055773b1db59
Author: Henry Castro 
Date:   Tue Dec 29 20:59:17 2015 -0400

loolwsd: close pipes

diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp
index 34343cb..7cdbf26 100644
--- a/loolwsd/LOOLBroker.cpp
+++ b/loolwsd/LOOLBroker.cpp
@@ -418,12 +418,10 @@ public:
 #endif
 Log::debug("Thread [" + thread_name + "] started.");
 
-while (true)
+while (!TerminationFlag)
 {
 if ( pStart == pEnd )
 {
-(void)poll(,1,-1);
-
 if (poll(, 1, -1) < 0)
 {
 Log::error("Failed to poll pipe [" + FIFO_FILE + "].");
@@ -558,6 +556,8 @@ static int createLibreOfficeKit(const bool sharePages, 
const std::string& loSubP
 
 if ( (nFIFOWriter = open(pipe.c_str(), O_WRONLY)) < 0 )
 {
+// TODO.  ill process state, that state should force close prison 
websockets and
+// kill, currently we have only "stop server state".
 Log::error("Error: failed to open pipe [" + pipe + "] write only. 
Abandoning child.");
 Poco::Process::requestTermination(child);
 return -1;
@@ -808,8 +808,7 @@ int main(int argc, char** argv)
 
 aPipe.start(pipeHandler);
 
-Log::info("loolbroker ready!");
-
+Log::info("loolbroker is ready.");
 
 unsigned timeoutCounter = 0;
 while (!TerminationFlag && !_childProcesses.empty())
@@ -823,6 +822,7 @@ int main(int argc, char** argv)
 if ((WIFEXITED(status) || WIFSIGNALED(status) || 
WTERMSIG(status) ) )
 {
 Log::error("Child [" + std::to_string(pid) + "] processes 
died.");
+
 forkMutex.lock();
 _childProcesses.erase(pid);
 _cacheURL.clear();
@@ -873,8 +873,13 @@ int main(int argc, char** argv)
 {
 Log::info("Requesting child process " + std::to_string(i.first) + " to 
terminate.");
 Process::requestTermination(i.first);
+close(i.second);
 }
 
+aPipe.join();
+close(readerChild);
+close(readerBroker);
+
 Log::info("Process [loolbroker] finished.");
 return 0;
 }
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index d8989f2..ce391ad 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -997,6 +997,8 @@ int LOOLWSD::main(const std::vector& /*args*/)
 if (LOOLWSD::doTest)
 inputThread.join();
 
+close(BrokerWritePipe);
+
 // stop the service, no more request
 srv.stop();
 srv2.stop();
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2015-12-28 Thread Ashod Nakashian
 loolwsd/LOOLBroker.cpp |   29 -
 loolwsd/LOOLWSD.cpp|9 ++---
 loolwsd/Util.hpp   |2 +-
 3 files changed, 35 insertions(+), 5 deletions(-)

New commits:
commit 9e9e2f60ef5b8b16fb4b85a3b6d8edaaa56aca0d
Author: Ashod Nakashian 
Date:   Mon Dec 28 18:24:29 2015 -0500

loolwsd: broker handles sigint and wsd removes childroot

Change-Id: Ie408bff7944ff0b9abfa8433b1e8ea6f62a9ab2c
Reviewed-on: https://gerrit.libreoffice.org/20999
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp
index 5c53025..624d536 100644
--- a/loolwsd/LOOLBroker.cpp
+++ b/loolwsd/LOOLBroker.cpp
@@ -62,6 +62,7 @@ const std::string FIFO_BROKER = "/tmp/loolbroker.fifo";
 const std::string BROKER_SUFIX = ".fifo";
 const std::string BROKER_PREFIX = "/tmp/lokit";
 
+static volatile bool TerminationFlag = false;
 static int readerChild = -1;
 static int readerBroker = -1;
 
@@ -75,6 +76,28 @@ static std::map _cacheURL;
 
 namespace
 {
+void handleSignal(int aSignal)
+{
+Log::info() << "Signal received: " << strsignal(aSignal) << Log::end;
+TerminationFlag = true;
+}
+
+void setSignals(bool isIgnored)
+{
+#ifdef __linux
+struct sigaction aSigAction;
+
+sigemptyset(_mask);
+aSigAction.sa_flags = 0;
+aSigAction.sa_handler = (isIgnored ? SIG_IGN : handleSignal);
+
+sigaction(SIGTERM, , NULL);
+sigaction(SIGINT, , NULL);
+sigaction(SIGQUIT, , NULL);
+sigaction(SIGHUP, , NULL);
+#endif
+}
+
 ThreadLocal sourceForLinkOrCopy;
 ThreadLocal destinationForLinkOrCopy;
 
@@ -601,6 +624,10 @@ int main(int argc, char** argv)
 // Initialization
 Log::initialize("brk");
 
+#ifdef __linux
+setSignals(false);
+#endif
+
 std::string childRoot;
 std::string loSubPath;
 std::string sysTemplate;
@@ -808,7 +835,7 @@ int main(int argc, char** argv)
 
 
 unsigned timeoutCounter = 0;
-while (_childProcesses.size() > 0)
+while (!TerminationFlag && !_childProcesses.empty())
 {
 int status;
 pid_t pid = waitpid(-1, , WUNTRACED | WNOHANG);
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 3b68fed..0f4e533 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -859,10 +859,11 @@ void LOOLWSD::startupBroker(const signed nBrokers)
 
 int LOOLWSD::main(const std::vector& /*args*/)
 {
+Log::initialize("wsd");
+
 Poco::Environment::set("LD_BIND_NOW", "1");
 Poco::Environment::set("LOK_VIEW_CALLBACK", "1");
 
-int status;
 #ifdef __linux
 char *locale = setlocale(LC_ALL, NULL);
 if (locale == NULL || std::strcmp(locale, "C") == 0)
@@ -871,8 +872,6 @@ int LOOLWSD::main(const std::vector& /*args*/)
 setSignals(false);
 #endif
 
-Log::initialize("wsd");
-
 if (access(cache.c_str(), R_OK | W_OK | X_OK) != 0)
 {
 Log::error("Unable to access cache [" + cache +
@@ -953,6 +952,7 @@ int LOOLWSD::main(const std::vector& /*args*/)
 waitForTerminationRequest();
 }
 
+int status = 0;
 unsigned timeoutCounter = 0;
 while (!LOOLWSD::isShutDown && !LOOLWSD::doTest && 
MasterProcessSession::_childProcesses.size() > 0)
 {
@@ -1015,6 +1015,9 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 // wait broker process finish
 waitpid(-1, , WUNTRACED);
 
+Log::info("Cleaning up childroot directory [" + childRoot + "].");
+Util::removeFile(childRoot, true);
+
 Log::info("loolwsd finished OK!");
 return Application::EXIT_OK;
 }
diff --git a/loolwsd/Util.hpp b/loolwsd/Util.hpp
index 89bf7a8..ac3d091 100644
--- a/loolwsd/Util.hpp
+++ b/loolwsd/Util.hpp
@@ -62,7 +62,7 @@ namespace Util
 }
 catch (const std::exception&)
 {
-// Already removed, nothing more to do.
+// Already removed or we don't care about failures.
 }
 }
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits