[Libreoffice-commits] online.git: Branch 'distro/collabora/milestone-7' - loolwsd/LOOLWSD.cpp loolwsd/LOOLWSD.hpp
Henry Castro
hcastro at collabora.com
Mon Feb 1 21:48:22 UTC 2016
loolwsd/LOOLWSD.cpp | 52 +++++++++++++++++++++++++++++++++++++++++++++-------
loolwsd/LOOLWSD.hpp | 6 ++++--
2 files changed, 49 insertions(+), 9 deletions(-)
New commits:
commit dbf816b9392db136f3a74c785a7704c3d5d42a05
Author: Henry Castro <hcastro at collabora.com>
Date: Mon Feb 1 17:46:56 2016 -0400
loolwsd: add fatal signals handler
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index db2ccac..8948da0 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -657,20 +657,38 @@ LOOLWSD::~LOOLWSD()
{
}
-void LOOLWSD::handleSignal(int aSignal)
+void LOOLWSD::handleTerminationSignal(const int aSignal)
{
- std::cout << Util::logPrefix() << "Signal received: " << strsignal(aSignal) << std::endl;
+ std::cout << Util::logPrefix() << "Signal received: "
+ << strsignal(aSignal) << std::endl;
LOOLWSD::isShutDown = true;
}
-void LOOLWSD::setSignals(bool isIgnored)
+void LOOLWSD::handleFatalSignal(const int aSignal)
+{
+ std::cout << Util::logPrefix() << "Fatal signal received: "
+ << strsignal(aSignal) << std::endl;
+ #ifdef __linux
+ struct sigaction aSigAction;
+
+ sigemptyset(&aSigAction.sa_mask);
+ aSigAction.sa_flags = 0;
+ aSigAction.sa_handler = SIG_DFL;
+
+ sigaction(aSignal, &aSigAction, NULL);
+ // let default handler process the signal
+ kill(Process::id(), aSignal);
+#endif
+}
+
+void LOOLWSD::setTerminationSignals()
{
#ifdef __linux
struct sigaction aSigAction;
sigemptyset(&aSigAction.sa_mask);
aSigAction.sa_flags = 0;
- aSigAction.sa_handler = (isIgnored ? SIG_IGN : handleSignal);
+ aSigAction.sa_handler = handleTerminationSignal;
sigaction(SIGTERM, &aSigAction, NULL);
sigaction(SIGINT, &aSigAction, NULL);
@@ -679,6 +697,23 @@ void LOOLWSD::setSignals(bool isIgnored)
#endif
}
+void LOOLWSD::setFatalSignals()
+{
+#ifdef __linux
+ struct sigaction aSigAction;
+
+ sigemptyset(&aSigAction.sa_mask);
+ aSigAction.sa_flags = 0;
+ aSigAction.sa_handler = handleFatalSignal;
+
+ sigaction(SIGSEGV, &aSigAction, NULL);
+ sigaction(SIGBUS, &aSigAction, NULL);
+ sigaction(SIGABRT, &aSigAction, NULL);
+ sigaction(SIGILL, &aSigAction, NULL);
+ sigaction(SIGFPE, &aSigAction, NULL);
+#endif
+}
+
void LOOLWSD::initialize(Application& self)
{
ServerApplication::initialize(self);
@@ -982,7 +1017,8 @@ void LOOLWSD::componentMain()
if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>("libreofficekit"), 0, 0, 0) != 0)
std::cout << Util::logPrefix() << "Cannot set thread name :" << strerror(errno) << std::endl;
- setSignals(false);
+ setTerminationSignals();
+ setFatalSignals();
#endif
try
@@ -1195,7 +1231,8 @@ void LOOLWSD::desktopMain()
if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>("loolbroker"), 0, 0, 0) != 0)
std::cout << Util::logPrefix() << "Cannot set thread name :" << strerror(errno) << std::endl;
- setSignals(false);
+ setTerminationSignals();
+ setFatalSignals();
#endif
_rng.seed(Process::id());
@@ -1309,7 +1346,8 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
if (locale == NULL || std::strcmp(locale, "C") == 0)
setlocale(LC_ALL, "en_US.utf8");
- setSignals(false);
+ setTerminationSignals();
+ setFatalSignals();
#endif
if (access(cache.c_str(), R_OK | W_OK | X_OK) != 0)
diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp
index f58917a..8d87cb0 100644
--- a/loolwsd/LOOLWSD.hpp
+++ b/loolwsd/LOOLWSD.hpp
@@ -56,8 +56,10 @@ public:
static const std::string LOKIT_PIDLOG;
protected:
- static void setSignals(bool bIgnore);
- static void handleSignal(int nSignal);
+ static void setTerminationSignals();
+ static void setFatalSignals();
+ static void handleTerminationSignal(const int nSignal);
+ static void handleFatalSignal(const int nSignal);
void initialize(Poco::Util::Application& self) override;
void uninitialize() override;
More information about the Libreoffice-commits
mailing list