[Libreoffice-commits] online.git: loolwsd/LOOLBroker.cpp loolwsd/LOOLWSD.cpp loolwsd/Util.hpp
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Mon Dec 28 15:39:31 PST 2015
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 <ashod.nakashian at collabora.co.uk>
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 <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
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<std::string, Process::PID> _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(&aSigAction.sa_mask);
+ aSigAction.sa_flags = 0;
+ aSigAction.sa_handler = (isIgnored ? SIG_IGN : handleSignal);
+
+ sigaction(SIGTERM, &aSigAction, NULL);
+ sigaction(SIGINT, &aSigAction, NULL);
+ sigaction(SIGQUIT, &aSigAction, NULL);
+ sigaction(SIGHUP, &aSigAction, NULL);
+#endif
+ }
+
ThreadLocal<std::string> sourceForLinkOrCopy;
ThreadLocal<Path> 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, &status, 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<std::string>& /*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<std::string>& /*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<std::string>& /*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<std::string>& /*args*/)
// wait broker process finish
waitpid(-1, &status, 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.
}
}
More information about the Libreoffice-commits
mailing list