common/SigUtil.cpp | 16 +++++++++++++++- common/SigUtil.hpp | 12 ++++++++++-- wsd/Admin.cpp | 4 ++-- wsd/ClientSession.cpp | 2 +- wsd/DocumentBroker.cpp | 10 +++++----- wsd/LOOLWSD.cpp | 14 +++++++------- 6 files changed, 40 insertions(+), 18 deletions(-)
New commits: commit 1263694944dffde36e12d42e72105fb10d10a4b1 Author: Miklos Vajna <[email protected]> AuthorDate: Mon Aug 12 09:03:16 2019 +0200 Commit: Miklos Vajna <[email protected]> CommitDate: Mon Aug 12 09:03:42 2019 +0200 common: wrap ShutdownRequestFlag in a getter function to avoid ODR violation Otherwise both loolwsd and unit-copy-paste.so would have a ShutdownRequestFlag: ==13663==ERROR: AddressSanitizer: odr-violation (0x00000208f860): [1] size=1 'ShutdownRequestFlag' ../common/SigUtil.cpp:60:19 [2] size=1 'ShutdownRequestFlag' common/SigUtil.cpp:60:19 These globals were registered at these points: [1]: #0 0x5f9a18 in __asan_register_globals.part.13 /home/vmiklos/git/libreoffice/lode/packages/llvm-472c6ef8b0f53061b049039f9775ab127beafbe4.src/compiler-rt/lib/asan/asan_globals.cc:365 #1 0x7f9b903f1d0b in asan.module_ctor (/home/vmiklos/git/libreoffice/online-san/test/../test/.libs/unit-copy-paste.so+0x60ad0b) [2]: #0 0x5f9a18 in __asan_register_globals.part.13 /home/vmiklos/git/libreoffice/lode/packages/llvm-472c6ef8b0f53061b049039f9775ab127beafbe4.src/compiler-rt/lib/asan/asan_globals.cc:365 #1 0xe2b9fe in asan.module_ctor (/home/vmiklos/git/libreoffice/online-san/loolwsd+0xe2b9fe) Change-Id: I247760325f804813249e814dbb4576493619dee7 diff --git a/common/SigUtil.cpp b/common/SigUtil.cpp index 49387b38d..61111b867 100644 --- a/common/SigUtil.cpp +++ b/common/SigUtil.cpp @@ -54,10 +54,24 @@ namespace SigUtil #if MOBILEAPP std::atomic<bool> MobileTerminationFlag(false); +namespace SigUtil +{ + bool getShutdownRequestFlag() + { + return ShutdownRequestFlag; + } +} #endif #if !MOBILEAPP -std::atomic<bool> ShutdownRequestFlag(false); +static std::atomic<bool> ShutdownRequestFlag(false); +namespace SigUtil +{ + std::atomic<bool>& getShutdownRequestFlag() + { + return ShutdownRequestFlag; + } +} std::mutex SigHandlerTrap; diff --git a/common/SigUtil.hpp b/common/SigUtil.hpp index ea7595ab6..9a366dc6d 100644 --- a/common/SigUtil.hpp +++ b/common/SigUtil.hpp @@ -14,10 +14,18 @@ #include <mutex> #if !MOBILEAPP -/// Flag to commence clean shutdown -extern std::atomic<bool> ShutdownRequestFlag; +namespace SigUtil +{ + /// Flag to commence clean shutdown + std::atomic<bool>& getShutdownRequestFlag(); +} #else static constexpr bool ShutdownRequestFlag(false); +namespace SigUtil +{ + /// Flag to commence clean shutdown + bool getShutdownRequestFlag(); +} #endif namespace SigUtil diff --git a/wsd/Admin.cpp b/wsd/Admin.cpp index 05babf1d2..cb8c43ceb 100644 --- a/wsd/Admin.cpp +++ b/wsd/Admin.cpp @@ -191,7 +191,7 @@ void AdminSocketHandler::handleMessage(bool /* fin */, WSOpCode /* code */, else if (tokens[0] == "shutdown") { LOG_INF("Shutdown requested by admin."); - ShutdownRequestFlag = true; + SigUtil::getShutdownRequestFlag() = true; SocketPoll::wakeupWorld(); return; } @@ -389,7 +389,7 @@ void Admin::pollingThread() lastMem = lastCPU; lastNet = lastCPU; - while (!isStop() && !SigUtil::getTerminationFlag() && !ShutdownRequestFlag) + while (!isStop() && !SigUtil::getTerminationFlag() && !SigUtil::getShutdownRequestFlag()) { const std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now(); diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp index c24f04f57..a382afbd9 100644 --- a/wsd/ClientSession.cpp +++ b/wsd/ClientSession.cpp @@ -1557,7 +1557,7 @@ void ClientSession::onDisconnect() // respond with close frame shutdown(); } - else if (!ShutdownRequestFlag) + else if (!SigUtil::getShutdownRequestFlag()) { // something wrong, with internal exceptions LOG_TRC("Abnormal close handshake."); diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp index 39e2be94c..deb9104b8 100644 --- a/wsd/DocumentBroker.cpp +++ b/wsd/DocumentBroker.cpp @@ -231,7 +231,7 @@ void DocumentBroker::pollThread() // Nominal time between retries, lest we busy-loop. getNewChild could also wait, so don't double that here. std::this_thread::sleep_for(std::chrono::milliseconds(CHILD_REBALANCE_INTERVAL_MS / 10)); } - while (!_stop && _poll->continuePolling() && !SigUtil::getTerminationFlag() && !ShutdownRequestFlag); + while (!_stop && _poll->continuePolling() && !SigUtil::getTerminationFlag() && !SigUtil::getShutdownRequestFlag()); #else _childProcess = getNewChild_Blocks(getPublicUri().getPath()); #endif @@ -324,9 +324,9 @@ void DocumentBroker::pollThread() continue; } - if (ShutdownRequestFlag || _closeRequest) + if (SigUtil::getShutdownRequestFlag() || _closeRequest) { - const std::string reason = ShutdownRequestFlag ? "recycling" : _closeReason; + const std::string reason = SigUtil::getShutdownRequestFlag() ? "recycling" : _closeReason; LOG_INF("Autosaving DocumentBroker for docKey [" << getDocKey() << "] for " << reason); if (!autoSave(isPossiblyModified())) { @@ -387,7 +387,7 @@ void DocumentBroker::pollThread() } LOG_INF("Finished polling doc [" << _docKey << "]. stop: " << _stop << ", continuePolling: " << - _poll->continuePolling() << ", ShutdownRequestFlag: " << ShutdownRequestFlag << + _poll->continuePolling() << ", ShutdownRequestFlag: " << SigUtil::getShutdownRequestFlag() << ", TerminationFlag: " << SigUtil::getTerminationFlag() << ", closeReason: " << _closeReason << ". Flushing socket."); if (_isModified) @@ -411,7 +411,7 @@ void DocumentBroker::pollThread() } LOG_INF("Finished flushing socket for doc [" << _docKey << "]. stop: " << _stop << ", continuePolling: " << - _poll->continuePolling() << ", ShutdownRequestFlag: " << ShutdownRequestFlag << + _poll->continuePolling() << ", ShutdownRequestFlag: " << SigUtil::getShutdownRequestFlag() << ", TerminationFlag: " << SigUtil::getTerminationFlag() << ". Terminating child with reason: [" << _closeReason << "]."); // Terminate properly while we can. diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp index 1493399f5..e053c4107 100644 --- a/wsd/LOOLWSD.cpp +++ b/wsd/LOOLWSD.cpp @@ -1406,7 +1406,7 @@ bool LOOLWSD::checkAndRestoreForKit() if (ForKitProcId == -1) { // Fire the ForKit process for the first time. - if (!ShutdownRequestFlag && !SigUtil::getTerminationFlag() && !createForKit()) + if (!SigUtil::getShutdownRequestFlag() && !SigUtil::getTerminationFlag() && !createForKit()) { // Should never fail. LOG_FTL("Failed to spawn loolforkit."); @@ -1435,7 +1435,7 @@ bool LOOLWSD::checkAndRestoreForKit() } // Spawn a new forkit and try to dust it off and resume. - if (!ShutdownRequestFlag && !SigUtil::getTerminationFlag() && !createForKit()) + if (!SigUtil::getShutdownRequestFlag() && !SigUtil::getTerminationFlag() && !createForKit()) { LOG_FTL("Failed to spawn forkit instance. Shutting down."); SigUtil::requestShutdown(); @@ -1469,7 +1469,7 @@ bool LOOLWSD::checkAndRestoreForKit() { // No child processes. // Spawn a new forkit and try to dust it off and resume. - if (!ShutdownRequestFlag && !SigUtil::getTerminationFlag() && !createForKit()) + if (!SigUtil::getShutdownRequestFlag() && !SigUtil::getTerminationFlag() && !createForKit()) { LOG_FTL("Failed to spawn forkit instance. Shutting down."); SigUtil::requestShutdown(); @@ -3101,7 +3101,7 @@ public: << (LOOLWSD::NoSeccomp ? "no" : "") << " api lockdown\n" #endif << " TerminationFlag: " << SigUtil::getTerminationFlag() << "\n" - << " isShuttingDown: " << ShutdownRequestFlag << "\n" + << " isShuttingDown: " << SigUtil::getShutdownRequestFlag() << "\n" << " NewChildren: " << NewChildren.size() << "\n" << " OutstandingForks: " << OutstandingForks << "\n" << " NumPreSpawnedChildren: " << LOOLWSD::NumPreSpawnedChildren << "\n"; @@ -3399,7 +3399,7 @@ int LOOLWSD::innerMain() const auto startStamp = std::chrono::steady_clock::now(); - while (!SigUtil::getTerminationFlag() && !ShutdownRequestFlag) + while (!SigUtil::getTerminationFlag() && !SigUtil::getShutdownRequestFlag()) { UnitWSD::get().invokeTest(); @@ -3430,14 +3430,14 @@ int LOOLWSD::innerMain() // Stop the listening to new connections // and wait until sockets close. LOG_INF("Stopping server socket listening. ShutdownRequestFlag: " << - ShutdownRequestFlag << ", TerminationFlag: " << SigUtil::getTerminationFlag()); + SigUtil::getShutdownRequestFlag() << ", TerminationFlag: " << SigUtil::getTerminationFlag()); // Wait until documents are saved and sessions closed. srv.stop(); // atexit handlers tend to free Admin before Documents LOG_INF("Cleaning up lingering documents."); - if (ShutdownRequestFlag || SigUtil::getTerminationFlag()) + if (SigUtil::getShutdownRequestFlag() || SigUtil::getTerminationFlag()) { // Don't stop the DocBroker, they will exit. const size_t sleepMs = 300; _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
