[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp loolwsd/Util.cpp loolwsd/Util.hpp
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Sun Oct 16 22:10:08 UTC 2016
loolwsd/LOOLKit.cpp | 7 +++----
loolwsd/Util.cpp | 3 +++
loolwsd/Util.hpp | 5 +++++
3 files changed, 11 insertions(+), 4 deletions(-)
New commits:
commit 57c5e55a4dd589216493cd4d88a71fb24e784d02
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Fri Oct 14 23:10:03 2016 -0400
loolwsd: trap signal handler to prevent premature exit
When upon cleanup we segfault we want to avoid
forcible exit using _Exit(). This was done by
an unconditional wait (sleep).
This patch changes that mechanism into a latch
(mutex) that traps the exit when the sig handler
is invoked, therby preventing exit as long as
necessary for the sighandler to finish.
Change-Id: Ifc8e972be12645a1b310d4cb4e3a4172afc31327
Reviewed-on: https://gerrit.libreoffice.org/29945
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index 94e5a5a..0ddcac5 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -1561,11 +1561,10 @@ void lokit_main(const std::string& childRoot,
Log::error(std::string("Exception: ") + exc.what());
}
- // Sleep a second here in case we get a fatal signal just when about to finish up, which sadly
- // seems to happen often, so that handleFatalSignal() in Util.cpp has time to produce a
- // backtrace.
- sleep(1);
+ // Trap the signal handler, if invoked,
+ // to prevent exiting.
Log::info("Process finished.");
+ std::unique_lock<std::mutex> lock(SigHandlerTrap);
std::_Exit(Application::EXIT_OK);
}
#endif
diff --git a/loolwsd/Util.cpp b/loolwsd/Util.cpp
index c367630..1f53d7e 100644
--- a/loolwsd/Util.cpp
+++ b/loolwsd/Util.cpp
@@ -50,6 +50,7 @@
#include "Util.hpp"
std::atomic<bool> TerminationFlag(false);
+std::mutex SigHandlerTrap;
namespace Util
{
@@ -393,6 +394,8 @@ namespace Util
static
void handleFatalSignal(const int signal)
{
+ std::unique_lock<std::mutex> lock(SigHandlerTrap);
+
Log::signalLogPrefix();
Log::signalLog(" Fatal signal received: ");
Log::signalLog(signalName(signal));
diff --git a/loolwsd/Util.hpp b/loolwsd/Util.hpp
index 7d73ecc..a55c70e 100644
--- a/loolwsd/Util.hpp
+++ b/loolwsd/Util.hpp
@@ -31,6 +31,11 @@
/// Flag to stop pump loops.
extern std::atomic<bool> TerminationFlag;
+/// Mutex to trap signal handler, if any,
+/// and prevent _Exit while collecting backtrace.
+extern std::mutex SigHandlerTrap;
+
+
namespace Util
{
namespace rng
More information about the Libreoffice-commits
mailing list