[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp |9 - 1 file changed, 8 insertions(+), 1 deletion(-) New commits: commit 98020193d40704cd762b78b29374b41b98091237 Author: Ashod Nakashian Date: Sat Nov 19 10:05:28 2016 -0500 loolwsd: add missing alertAllUsers definition in LOOLKit Change-Id: I75a08c3c856cc4ff783ea3a805283c7d81c02249 Reviewed-on: https://gerrit.libreoffice.org/31000 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 4577003..7407384 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -1644,10 +1644,17 @@ namespace Util { #ifndef BUILDING_TESTS + +void alertAllUsers(const std::string& msg) +{ +document->sendTextFrame(msg); +} + void alertAllUsers(const std::string& cmd, const std::string& kind) { -document->sendTextFrame("errortoall: cmd=" + cmd + " kind=" + kind); +alertAllUsers("errortoall: cmd=" + cmd + " kind=" + kind); } + #endif } ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp loolwsd/LOOLWSD.cpp loolwsd/Util.cpp loolwsd/Util.hpp
loolwsd/LOOLKit.cpp | 10 +- loolwsd/LOOLWSD.cpp |3 ++- loolwsd/Util.cpp| 13 - loolwsd/Util.hpp|5 + 4 files changed, 24 insertions(+), 7 deletions(-) New commits: commit 47d040f34532e1b913a64d340dd891601a83072b Author: Ashod Nakashian Date: Sun Nov 13 16:13:36 2016 -0500 loolwsd: handle SIGINT in WSD only CONTROL-C is now handled by WSD only to have full control over server shutting down. Also set signal handlers first thing to trap any early failures. Change-Id: Ifc5c93b9dd2aef288eed0ed36c600a639dbc6a44 Reviewed-on: https://gerrit.libreoffice.org/30826 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 507ad94..17bd15c 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -1279,6 +1279,11 @@ void lokit_main(const std::string& childRoot, bool queryVersion, bool displayVersion) { +Util::setFatalSignals(); +Util::setTerminationSignals(); + +Util::setThreadName("loolkit"); + // Reinitialize logging when forked. const bool logToFile = std::getenv("LOOL_LOGFILE"); const char* logFilename = std::getenv("LOOL_LOGFILENAME"); @@ -1304,13 +1309,8 @@ void lokit_main(const std::string& childRoot, static const std::string pid = std::to_string(Process::id()); static const std::string jailId = pid; -Util::setThreadName("loolkit"); - LOG_DBG("Process started."); -Util::setTerminationSignals(); -Util::setFatalSignals(); - std::string userdir_url; std::string instdir_path; diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index 177b155..4655a91 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -1846,8 +1846,9 @@ Process::PID LOOLWSD::createForKit() int LOOLWSD::main(const std::vector& /*args*/) { -Util::setTerminationSignals(); Util::setFatalSignals(); +Util::setTerminationSignals(); +Util::setInterruptionSignal(); // down-pay all the forkit linking cost once & early. Environment::set("LD_BIND_NOW", "1"); diff --git a/loolwsd/Util.cpp b/loolwsd/Util.cpp index b5c26a7..deb2819 100644 --- a/loolwsd/Util.cpp +++ b/loolwsd/Util.cpp @@ -218,11 +218,22 @@ namespace Util action.sa_handler = handleTerminationSignal; sigaction(SIGTERM, &action, nullptr); -sigaction(SIGINT, &action, nullptr); sigaction(SIGQUIT, &action, nullptr); sigaction(SIGHUP, &action, nullptr); } +/// Handle SIGINT, should be set by WSD only. +void setInterruptionSignal() +{ +struct sigaction action; + +sigemptyset(&action.sa_mask); +action.sa_flags = 0; +action.sa_handler = handleTerminationSignal; + +sigaction(SIGINT, &action, nullptr); +} + static char FatalGdbString[256] = { '\0' }; static diff --git a/loolwsd/Util.hpp b/loolwsd/Util.hpp index 93c95f7..2303a65 100644 --- a/loolwsd/Util.hpp +++ b/loolwsd/Util.hpp @@ -84,8 +84,13 @@ namespace Util /// Trap signals to cleanup and exit the process gracefully. void setTerminationSignals(); + +/// Trap all fatal signals to assist debugging. void setFatalSignals(); +/// Trap SIGINT, should be set by WSD only. +void setInterruptionSignal(); + void requestTermination(const Poco::Process::PID& pid); /// Kills a child process and returns true when ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 38 ++ 1 file changed, 18 insertions(+), 20 deletions(-) New commits: commit 871a67bd98eedf7ccf087b1220fbdc757c314fbc Author: Ashod Nakashian Date: Fri Nov 4 00:55:08 2016 -0400 loolwsd: avoid side bookkeeping Change-Id: I7ad2cbf45c07173447c4e80dcf06f0155de904e9 Reviewed-on: https://gerrit.libreoffice.org/30554 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index cadd10d..acdc2e5 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -290,8 +290,7 @@ public: _docPasswordType(PasswordType::ToView), _stop(false), _mutex(), -_isLoading(0), -_clientViews(0) +_isLoading(0) { Log::info("Document ctor for url [" + _url + "] on child [" + _jailId + "]."); assert(_loKit && _loKit->get()); @@ -301,8 +300,8 @@ public: ~Document() { -Log::info("~Document dtor for url [" + _url + "] on child [" + _jailId + - "]. There are " + std::to_string(_clientViews) + " views."); +LOG_INF("~Document dtor for url [" << _url << "] on child [" << _jailId << + "]. There are " << _sessions.size() << " views."); // Wait for the callback worker to finish. _stop = true; @@ -325,7 +324,7 @@ public: return true; } -LOG_INF("Creating " << (_clientViews ? "new" : "first") << +LOG_INF("Creating " << (_sessions.empty() ? "first" : "new") << " session for url: " << _url << " for sessionId: " << sessionId << " on jailId: " << _jailId); @@ -767,9 +766,11 @@ private: const std::string& renderOpts, const bool haveDocPassword) override { -Log::info("Session " + sessionId + " is loading. " + std::to_string(_clientViews) + " views loaded."); - std::unique_lock lock(_mutex); + +LOG_INF("Loading session [" << sessionId << "] on url [" << uri << +"] is loading. " << _sessions.size() << " views loaded."); + while (_isLoading) { _cvLoading.wait(lock); @@ -796,7 +797,6 @@ private: // Done loading, let the next one in (if any). assert(_loKitDocument && _loKitDocument->get() && "Uninitialized lok::Document instance"); lock.lock(); -++_clientViews; --_isLoading; _cvLoading.notify_one(); @@ -808,7 +808,8 @@ private: const auto& sessionId = session.getId(); LOG_INF("Unloading session [" << sessionId << "] on url [" << _url << "]."); -_tileQueue->removeCursorPosition(session.getViewId()); +const auto viewId = session.getViewId(); +_tileQueue->removeCursorPosition(viewId); if (_loKitDocument == nullptr) { @@ -816,15 +817,8 @@ private: return; } ---_clientViews; -Log::info() << "Document [" << _url << "] session [" -<< sessionId << "] unloaded, " << _clientViews -<< " view" << (_clientViews != 1 ? "s" : "") -<< Log::end; - std::unique_lock lockLokDoc(_loKitDocument->getLock()); -const auto viewId = session.getViewId(); _loKitDocument->setView(viewId); _loKitDocument->registerCallback(nullptr, nullptr); _loKitDocument->destroyView(viewId); @@ -837,6 +831,10 @@ private: std::vector viewIds(viewCount); _loKitDocument->getViewIds(viewIds.data(), viewCount); +LOG_INF("Document [" << _url << "] session [" << +sessionId << "] unloaded. Have " << viewCount << +" view" << (viewCount != 1 ? "s" : "")); + lockLokDoc.unlock(); // Broadcast updated view info @@ -1109,9 +1107,10 @@ private: std::unique_ptr(new CallbackDescriptor({ this, viewId }))); _loKitDocument->registerCallback(ViewCallback, _viewIdToCallbackDescr[viewId].get()); -Log::info() << "Document [" << _url << "] view [" -<< viewId << "] loaded, leaving " -<< (_clientViews + 1) << " views." << Log::end; +const int viewCount = _loKitDocument->getViewsCount(); +LOG_INF("Document [" << _url << "] view [" << + viewId << "] loaded. Have " << viewCount << + " view" << (viewCount != 1 ? "s." : ".")); return _loKitDocument; } @@ -1273,7 +1272,6 @@ private: std::map> _sessions; std::map _oldSessionIds; Poco::Thread _callbackThread; -std::atomic_size_t _clientViews; }; void documentViewCallback(const int nType, const char* pPayload, void* pData) ___ Libreoffice-commits mailing lis
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 21 + 1 file changed, 9 insertions(+), 12 deletions(-) New commits: commit b6fae38f17078b3e9b1b6dc267e5402ecc5d7b2f Author: Ashod Nakashian Date: Fri Nov 4 00:30:27 2016 -0400 loolwsd: simplified createSession Change-Id: I2ebb37cae61d9625731b48ea6b9ce31646ad3e42 Reviewed-on: https://gerrit.libreoffice.org/30552 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 66319c3..c257e0b 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -319,29 +319,26 @@ public: try { -const auto& it = _sessions.find(sessionId); -if (it != _sessions.end()) +if (_sessions.find(sessionId) != _sessions.end()) { -Log::warn("Session [" + sessionId + "] is already running."); +LOG_WRN("Session [" << sessionId << "] on url [" << _url << "] already exists."); return true; } -Log::info() << "Creating " << (_clientViews ? "new" : "first") -<< " view for url: " << _url << " for sessionId: " << sessionId -<< " on jailId: " << _jailId << Log::end; +LOG_INF("Creating " << (_clientViews ? "new" : "first") << +" session for url: " << _url << " for sessionId: " << +sessionId << " on jailId: " << _jailId); auto session = std::make_shared(sessionId, _jailId, *this); -if (!_sessions.emplace(sessionId, session).second) -{ -Log::error("Session already exists for child: " + _jailId + ", session: " + sessionId); -} +_sessions.emplace(sessionId, session); -Log::debug("Sessions: " + std::to_string(_sessions.size())); +LOG_DBG("Sessions: " << _sessions.size()); return true; } catch (const std::exception& ex) { -Log::error("Exception while creating session [" + sessionId + "] on url [" + _url + "] - '" + ex.what() + "'."); +LOG_ERR("Exception while creating session [" << sessionId << +"] on url [" << _url << "] - '" << ex.what() << "'."); return false; } } ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) New commits: commit 1f14642f8c1197ceb65a62c730326a61e23e5284 Author: Pranav Kant Date: Wed Oct 26 20:11:52 2016 +0530 loolwsd: This is sessionId, not viewId Change-Id: I98026369602fe6e25f72fe743e4f67b821ef0418 diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index b88126a..07f2d25 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -1123,15 +1123,15 @@ private: Log::trace("Forwarding payload to " + prefix + ' ' + message); std::string name; -std::string viewId; -if (LOOLProtocol::parseNameValuePair(prefix, name, viewId, '-') && name == "child") +std::string sessionId; +if (LOOLProtocol::parseNameValuePair(prefix, name, sessionId, '-') && name == "child") { -const auto it = _sessions.find(viewId); +const auto it = _sessions.find(sessionId); if (it != _sessions.end()) { if (message == "disconnect") { -Log::debug("Removing ChildSession " + viewId); +Log::debug("Removing ChildSession " + sessionId); _oldSessionIds[it->second->getViewId()] = it->second->getViewUserName(); _sessions.erase(it); return true; @@ -1144,7 +1144,7 @@ private: } } -Log::warn() << "Child session [" << viewId << "] not found to forward message: " << message << Log::end; +Log::warn() << "Child session [" << sessionId << "] not found to forward message: " << message << Log::end; } else { ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp loolwsd/Util.cpp loolwsd/Util.hpp
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 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 Tested-by: Ashod Nakashian 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 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 TerminationFlag(false); +std::mutex SigHandlerTrap; namespace Util { @@ -393,6 +394,8 @@ namespace Util static void handleFatalSignal(const int signal) { +std::unique_lock 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 TerminationFlag; +/// Mutex to trap signal handler, if any, +/// and prevent _Exit while collecting backtrace. +extern std::mutex SigHandlerTrap; + + namespace Util { namespace rng ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 22 +- 1 file changed, 1 insertion(+), 21 deletions(-) New commits: commit 4ca15894dfb2cdbe0d25dd033f7eb90144a8ae73 Author: Ashod Nakashian Date: Fri Oct 14 23:04:12 2016 -0400 loolwsd: only forkit cleans up the jail directory No need to do a partial cleanup in the kit when forkit recycles the disk. This avoid both programatic errors (as the comments in the removed code explains) as well as hammering the disk from multiple processes. By leaving all disk cleanup to forkit we guarantee safety and that only one process does disk cleanup, and sequentially at that. N.B. Kit processes are still responsible for setting up the jail and the LO binaries etc. So disk IO is not strictly sequential from a single process. Change-Id: Ia6768ab87df71a83a6676c3d52da3d6797f717fc Reviewed-on: https://gerrit.libreoffice.org/29944 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 172da5c..94e5a5a 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -1548,27 +1548,7 @@ void lokit_main(const std::string& childRoot, return TerminationFlag.load(); }); -// Clean up jail if we created one -if (bRunInsideJail && !jailPath.isRelative()) -{ -// In theory we should here do Util::removeFile("/", true), because we are inside the -// chroot jail, and all of it can be removed now when we are exiting. (At least the root -// of the chroot jail probably would not be removed even if we tried, so we still would -// need to complete the cleanup in loolforkit.) - -// But: It is way too risky to actually do that (effectively, "rm -rf /") as it would -// trash a developer's machine if something goes wrong while hacking and debugging and -// the process isn't in a chroot after all when it comes here. - -// So just remove what we can reasonably safely assume won't exist as global pathnames -// on a developer's machine, loSubpath (typically "/lo") and JAILED_DOCUMENT_ROOT -// ("/user/docs/"). - -Log::info("Removing '/" + loSubPath + "'"); -Util::removeFile("/" + loSubPath, true); -Log::info("Removing '" + std::string(JAILED_DOCUMENT_ROOT) + "'"); -Util::removeFile(std::string(JAILED_DOCUMENT_ROOT), true); -} +// Let forkit handle the jail cleanup. } catch (const Exception& exc) { ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 35 ++- 1 file changed, 34 insertions(+), 1 deletion(-) New commits: commit 3963382913cd5463f720995fb76af0435eeedf49 Author: Ashod Nakashian Date: Sat Oct 8 13:34:53 2016 -0400 loolwsd: forward child messages to the respective ChildSession Change-Id: Ib1e0c51effd046a2f0d0e5708c501b6414caa81a Reviewed-on: https://gerrit.libreoffice.org/29635 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 575b947..a2fbf97 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -1225,6 +1225,35 @@ private: return _loKitDocument; } +bool forwardToChild(const std::string& prefix, const std::vector& payload) +{ +const std::string message(payload.data() + prefix.size(), payload.size() - prefix.size()); +Log::trace("Forwarding payload to client: " + message); + +std::string name; +int viewId = -1; +if (LOOLProtocol::parseNameIntegerPair(prefix, name, viewId, '-') && name == "child") +{ +const auto it = _connections.find(viewId); +if (it != _connections.end() && it->second->isRunning()) +{ +auto session = it->second->getSession(); +if (session && session->getViewId() == viewId) +{ +return session->handleInput(message.data(), message.size()); +} +} + +Log::warn() << "Child session [" << viewId << "] not found to forward message: " << message << Log::end; +} +else +{ +Log::error("Failed to parse prefix of forward-to-child message: " + message); +} + +return false; +} + void run() override { Util::setThreadName("lok_handler"); @@ -1235,7 +1264,7 @@ private: { while (!_stop && !TerminationFlag) { -const auto input = _tileQueue->get(); +const TileQueue::Payload input = _tileQueue->get(); if (_stop || TerminationFlag) { break; @@ -1258,6 +1287,10 @@ private: { renderCombinedTiles(tokens, _ws); } +else if (LOOLProtocol::getFirstToken(tokens[0], '-') == "child") +{ +forwardToChild(tokens[0], input); +} else if (tokens[0] == "callback") { int viewId = std::stoi(tokens[1]); // -1 means broadcast ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp |3 +++ 1 file changed, 3 insertions(+) New commits: commit 5b3e5f73a2e9a0cc65821d0f4324782b622ed2f7 Author: Ashod Nakashian Date: Thu Oct 6 01:52:14 2016 -0400 loolwsd: trade view creation and assert lock ownership Change-Id: Ib593bec4d6e6b810d5f6cfb4bdf7d3f1212709b4 Reviewed-on: https://gerrit.libreoffice.org/29549 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index d2cfdb5..9f5ba59 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -1179,8 +1179,11 @@ private: Log::info("Loading view to document from URI: [" + uri + "] for session [" + sessionId + "]."); _loKitDocument->createView(); +Log::trace("View created."); } +Util::assertIsLocked(lockLokDoc); + Object::Ptr renderOptsObj = new Object(); // Fill the object with renderoptions, if any ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp |3 --- 1 file changed, 3 deletions(-) New commits: commit fed97b97a795f0b4794f37bd5d47e4a81e311b54 Author: Miklos Vajna Date: Tue Sep 27 09:46:24 2016 +0200 LOOLKit: remove unused unsing declarations Change-Id: I6a0efca4dd87694aaa3d32500a56c3a5d246b028 diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 0b03fed..e926056 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -68,7 +68,6 @@ typedef int (LokHookPreInit) (const char *install_path, const char *user_profile_path); -using Poco::AutoPtr; using Poco::Exception; using Poco::File; using Poco::JSON::Array; @@ -79,8 +78,6 @@ using Poco::Net::HTTPRequest; using Poco::Net::HTTPResponse; using Poco::Net::NetException; using Poco::Net::WebSocket; -using Poco::Notification; -using Poco::NotificationQueue; using Poco::Path; using Poco::Process; using Poco::Runnable; ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp |2 +- 1 file changed, 1 insertion(+), 1 deletion(-) New commits: commit fa697d843ee3fce2ee1cb3d76854f5ed86e4f828 Author: Tor Lillqvist Date: Tue Sep 27 09:29:18 2016 +0300 Remove reference to non-public bugzilla diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 153bd80..0b03fed 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -543,7 +543,7 @@ public: // If there are no live sessions, we don't need to do anything at all and can just // bluntly exit, no need to clean up our own data structures. Also, there is a bug that // causes the deadSessions.clear() call below to crash in some situations when the last -// session is being removed, see bccu#2035. +// session is being removed. for (auto it = _connections.cbegin(); it != _connections.cend(); ++it) { if (it->second->isRunning()) ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 36 1 file changed, 28 insertions(+), 8 deletions(-) New commits: commit e0c5f260155ce38bc9f10b0120fed4c39a52beef Author: Tor Lillqvist Date: Mon Sep 26 17:28:14 2016 +0300 bccu#2035: Work around crash by just exiting before it happens diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index cc35ad4..153bd80 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -530,6 +530,7 @@ public: size_t purgeSessions() { std::vector> deadSessions; +size_t numRunning = 0; size_t num_connections = 0; { std::unique_lock lock(_mutex, std::defer_lock); @@ -539,22 +540,41 @@ public: return -1; } -for (auto it = _connections.cbegin(); it != _connections.cend(); ) +// If there are no live sessions, we don't need to do anything at all and can just +// bluntly exit, no need to clean up our own data structures. Also, there is a bug that +// causes the deadSessions.clear() call below to crash in some situations when the last +// session is being removed, see bccu#2035. +for (auto it = _connections.cbegin(); it != _connections.cend(); ++it) { -if (!it->second->isRunning()) -{ -deadSessions.push_back(it->second->getSession()); -it = _connections.erase(it); -} -else +if (it->second->isRunning()) +numRunning++; +} + +if (numRunning > 0) +{ +for (auto it = _connections.cbegin(); it != _connections.cend(); ) { -++it; +if (!it->second->isRunning()) +{ +deadSessions.push_back(it->second->getSession()); +it = _connections.erase(it); +} +else +{ +++it; +} } } num_connections = _connections.size(); } +if (numRunning == 0) +{ +Log::info("No more sessions, exiting bluntly"); +std::_Exit(Application::EXIT_OK); +} + // Don't destroy sessions while holding our lock. // We may deadlock if a session is waiting on us // during callback initiated while handling a command ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp loolwsd/LOOLWSD.cpp
loolwsd/LOOLKit.cpp | 10 +- loolwsd/LOOLWSD.cpp | 13 + 2 files changed, 22 insertions(+), 1 deletion(-) New commits: commit b8317e7b34120417885833926852657d4e7bce07 Author: Ashod Nakashian Date: Wed Sep 21 18:12:34 2016 -0400 loolwsd: lokit process logs to file if configured Pass the log-to-file config to the kit processes using envars. Change-Id: Ida79c35ab02d8038685153805be780359bfbe97e Reviewed-on: https://gerrit.libreoffice.org/29161 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 36b7817..7c9f451 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -1349,7 +1349,15 @@ void lokit_main(const std::string& childRoot, bool queryVersion) { // Reinitialize logging when forked. -Log::initialize("kit", getenv("LOOL_LOGLEVEL"), getenv("LOOL_LOGCOLOR")); +const bool logToFile = getenv("LOOL_LOGFILE"); +const auto logFilename = getenv("LOOL_LOGFILENAME"); +std::map logProperties; +if (logToFile && logFilename) +{ +logProperties["path"] = std::string(logFilename); +} + +Log::initialize("kit", getenv("LOOL_LOGLEVEL"), getenv("LOOL_LOGCOLOR"), logToFile, logProperties); Util::rng::reseed(); assert(!childRoot.empty()); diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index 266ac7c..15e9eca 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -1403,7 +1403,9 @@ void LOOLWSD::initialize(Application& self) setenv("LOOL_LOGLEVEL", logLevel.c_str(), true); const auto withColor = !std::getenv("LOOL_NO_LOGCOLOR") && getConfigValue(conf, "logging.color", true); if (withColor) +{ setenv("LOOL_LOGCOLOR", "1", true); +} const auto logToFile = getConfigValue(conf, "logging.file[@enable]", false); std::map logProperties; @@ -1422,6 +1424,17 @@ void LOOLWSD::initialize(Application& self) } } +// Setup the logfile envar for the kit processes. +if (logToFile) +{ +setenv("LOOL_LOGFILE", "1", true); +const auto it = logProperties.find("path"); +if (it != logProperties.end()) +{ +setenv("LOOL_LOGFILENAME", it->second.c_str(), true); +} +} + Log::initialize("wsd", logLevel, withColor, logToFile, logProperties); #if ENABLE_SSL ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp loolwsd/MessageQueue.cpp loolwsd/TileCache.cpp
loolwsd/LOOLKit.cpp |9 +++-- loolwsd/MessageQueue.cpp |4 ++-- loolwsd/TileCache.cpp|1 + 3 files changed, 10 insertions(+), 4 deletions(-) New commits: commit 1641f756b2ee15e742e5a3545a074bceea8d9ee4 Author: Ashod Nakashian Date: Wed Sep 21 09:09:35 2016 -0400 loolwsd: improved logging Change-Id: I1a1559754efcb0614875dc76ae0637ed6dc1ba77 Reviewed-on: https://gerrit.libreoffice.org/29160 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 0d7b1ff..36b7817 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -666,13 +666,16 @@ public: return; } +const double area = tile.getWidth() * tile.getHeight(); Timestamp timestamp; _loKitDocument->paintPartTile(pixmap.data(), tile.getPart(), tile.getWidth(), tile.getHeight(), tile.getTilePosX(), tile.getTilePosY(), tile.getTileWidth(), tile.getTileHeight()); +const auto elapsed = timestamp.elapsed(); Log::trace() << "paintTile at (" << tile.getPart() << ',' << tile.getTilePosX() << ',' << tile.getTilePosY() - << ") " << "ver: " << tile.getVersion() << " rendered in " << (timestamp.elapsed()/1000.) << " ms" << Log::end; + << ") " << "ver: " << tile.getVersion() << " rendered in " << (elapsed/1000.) + << " ms (" << area / elapsed << " MP/s)." << Log::end; const auto mode = static_cast(_loKitDocument->getTileMode()); if (!png::encodeBufferToPNG(pixmap.data(), tile.getWidth(), tile.getHeight(), output, mode)) @@ -741,14 +744,16 @@ public: return; } +const double area = pixmapWidth * pixmapHeight; Timestamp timestamp; _loKitDocument->paintPartTile(pixmap.data(), tileCombined.getPart(), pixmapWidth, pixmapHeight, renderArea.getLeft(), renderArea.getTop(), renderArea.getWidth(), renderArea.getHeight()); +const auto elapsed = timestamp.elapsed(); Log::debug() << "paintTile (combined) at (" << renderArea.getLeft() << ", " << renderArea.getTop() << "), (" << renderArea.getWidth() << ", " << renderArea.getHeight() << ") ver: " << tileCombined.getVersion() - << " rendered in " << (timestamp.elapsed()/1000.) << " ms." << Log::end; + << " rendered in " << (elapsed/1000.) << " ms (" << area / elapsed << " MP/s)." << Log::end; const auto mode = static_cast(_loKitDocument->getTileMode()); std::vector output; diff --git a/loolwsd/MessageQueue.cpp b/loolwsd/MessageQueue.cpp index 0a4c96d..75d6441 100644 --- a/loolwsd/MessageQueue.cpp +++ b/loolwsd/MessageQueue.cpp @@ -146,10 +146,10 @@ void TileQueue::put_impl(const Payload& value) auto& it = _queue[i]; const std::string old(it.data(), it.size()); const auto oldMsg = old.substr(0, old.find(" ver")); -Log::trace() << "TileQueue #" << i << ": " << oldMsg << Log::end; +Log::trace() << "TileQueue #" << i << ": " << old << Log::end; if (newMsg == oldMsg) { -Log::debug() << "Replacing duplicate tile: " << oldMsg << " -> " << newMsg << Log::end; +Log::debug() << "Replacing duplicate tile: " << old << " -> " << msg << Log::end; _queue[i] = value; if (priority(msg)) diff --git a/loolwsd/TileCache.cpp b/loolwsd/TileCache.cpp index 6a2053f..88ccaf5 100644 --- a/loolwsd/TileCache.cpp +++ b/loolwsd/TileCache.cpp @@ -330,6 +330,7 @@ void TileCache::invalidateTiles(const std::string& tiles) } else if (tokens.count() != 6) { +Log::error("Unexpected invalidatetiles request: " + tiles); return; } else ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp loolwsd/MessageQueue.cpp
loolwsd/LOOLKit.cpp | 17 +++-- loolwsd/MessageQueue.cpp | 33 + 2 files changed, 36 insertions(+), 14 deletions(-) New commits: commit 0326aa4304e866bf346aaa90697a49b43f0d9d74 Author: Ashod Nakashian Date: Tue Sep 20 19:59:06 2016 -0400 loolwsd: cancel individual tiles Change-Id: I18faee319fc12de2151460afbb054b8509578579 Reviewed-on: https://gerrit.libreoffice.org/29120 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 3b4e39b..5eb7d42 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -1547,7 +1547,7 @@ void lokit_main(const std::string& childRoot, Log::debug("CreateSession failed."); } } -else if (tokens[0] == "tile") +else if (tokens[0] == "tile" || tokens[0] == "tilecombine" || tokens[0] == "canceltiles") { if (document) { @@ -1555,18 +1555,7 @@ void lokit_main(const std::string& childRoot, } else { -Log::warn("No document while processing tile request."); -} -} -else if (tokens[0] == "tilecombine") -{ -if (document) -{ -queue->put(message); -} -else -{ -Log::warn("No document while processing tilecombine request."); +Log::warn("No document while processing " + tokens[0] + " request."); } } else if (document && document->canDiscard()) @@ -1576,7 +1565,7 @@ void lokit_main(const std::string& childRoot, } else { -Log::info("Bad or unknown token [" + tokens[0] + "]"); +Log::error("Bad or unknown token [" + tokens[0] + "]"); } return true; diff --git a/loolwsd/MessageQueue.cpp b/loolwsd/MessageQueue.cpp index 7e81608..0a4c96d 100644 --- a/loolwsd/MessageQueue.cpp +++ b/loolwsd/MessageQueue.cpp @@ -11,9 +11,13 @@ #include +#include + #include #include +using Poco::StringTokenizer; + MessageQueue::~MessageQueue() { clear(); @@ -102,6 +106,35 @@ void TileQueue::put_impl(const Payload& value) { const auto msg = std::string(value.data(), value.size()); Log::trace() << "Putting [" << msg << "]" << Log::end; + +if (msg.compare(0, 11, "canceltiles") == 0) +{ +Log::trace("Processing " + msg); +Log::trace() << "Before canceltiles have " << _queue.size() << " in queue." << Log::end; +const auto seqs = msg.substr(12); +StringTokenizer tokens(seqs, ",", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM); +_queue.erase(std::remove_if(_queue.begin(), _queue.end(), +[&tokens](const Payload& v) +{ +const std::string s(v.data(), v.size()); +for (size_t i = 0; i < tokens.count(); ++i) +{ +if (s.find("ver=" + tokens[i]) != std::string::npos) +{ +Log::trace("Matched " + tokens[i] + ", Removing [" + s + "]"); +return true; +} +} + +return false; + +}), _queue.end()); + +// Don't push canceltiles into the queue. +Log::trace() << "After canceltiles have " << _queue.size() << " in queue." << Log::end; +return; +} + if (!_queue.empty()) { if (msg.compare(0, 4, "tile") == 0 || msg.compare(0, 10, "tilecombine") == 0) ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp loolwsd/MessageQueue.cpp loolwsd/MessageQueue.hpp loolwsd/TileDesc.hpp
loolwsd/LOOLKit.cpp |4 ++ loolwsd/MessageQueue.cpp | 74 --- loolwsd/MessageQueue.hpp |4 +- loolwsd/TileDesc.hpp | 42 ++ 4 files changed, 113 insertions(+), 11 deletions(-) New commits: commit e9f37433d7aafb0ac91e240cc4adab758036508f Author: Ashod Nakashian Date: Thu Sep 15 08:40:26 2016 -0400 loolwsd: combine tiles before rendering to reduce latency Change-Id: I5af2d2a9ddf3b5a3db5bc5f0835687d7cae5b17c Reviewed-on: https://gerrit.libreoffice.org/29115 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index a04945c..3b4e39b 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -1279,6 +1279,10 @@ private: { pThis->renderCombinedTiles(tokens, pThis->_ws); } +else +{ +Log::error("Unexpected tile request: [" + message + "]."); +} } } catch (const std::exception& exc) diff --git a/loolwsd/MessageQueue.cpp b/loolwsd/MessageQueue.cpp index 0660d2b..16946e2 100644 --- a/loolwsd/MessageQueue.cpp +++ b/loolwsd/MessageQueue.cpp @@ -48,6 +48,8 @@ void MessageQueue::remove_if(const std::function& pred) void MessageQueue::put_impl(const Payload& value) { +const auto msg = std::string(value.data(), value.size()); +Log::trace() << "Pushing into MQ [" << msg << "]" << Log::end; _queue.push_back(value); } @@ -73,6 +75,8 @@ void BasicTileQueue::put_impl(const Payload& value) const auto msg = std::string(&value[0], value.size()); if (msg == "canceltiles") { +Log::error("Unexpected canceltiles!"); + // remove all the existing tiles from the queue _queue.erase(std::remove_if(_queue.begin(), _queue.end(), [](const Payload& v) @@ -104,16 +108,6 @@ void TileQueue::put_impl(const Payload& value) { const auto newMsg = msg.substr(0, msg.find(" ver")); -// TODO: implement a real re-ordering here, so that the tiles closest to -// the cursor are returned first. -// * we will want to put just a general "tile" message to the queue -// * add a std::set that handles the tiles -// * change the get_impl() to decide which tile is the correct one to -// be returned -// * we will also need to be informed about the position of the cursor -// so that get_impl() returns optimal results -// -// For now: just don't put duplicates into the queue for (size_t i = 0; i < _queue.size(); ++i) { auto& it = _queue[i]; @@ -201,4 +195,64 @@ bool TileQueue::priority(const std::string& tileMsg) return false; } +MessageQueue::Payload TileQueue::get_impl() +{ +std::vector tiles; +const auto front = _queue.front(); +_queue.pop_front(); + +auto msg = std::string(front.data(), front.size()); +Log::trace() << "MessageQueue Get, Size: " << _queue.size() << ", Front: " << msg << Log::end; + +if (msg.compare(0, 5, "tile ") != 0 || msg.find("id=") != std::string::npos) +{ +// Don't combine non-tiles or tiles with id. +Log::trace() << "MessageQueue res: " << msg << Log::end; +return front; +} + +tiles.emplace_back(TileDesc::parse(msg)); + +// Combine as many tiles as possible with the top one. +for (size_t i = 0; i < _queue.size(); ) +{ +auto& it = _queue[i]; +msg = std::string(it.data(), it.size()); +if (msg.compare(0, 5, "tile ") != 0 || +msg.find("id=") != std::string::npos) +{ +// Don't combine non-tiles or tiles with id. +continue; +} + +auto tile2 = TileDesc::parse(msg); +bool found = false; +Log::trace() << "combining?: " << msg << Log::end; + +// Check if adjacent tiles. +for (auto& tile : tiles) +{ +if (tile.isAdjacent(tile2)) +{ +tiles.emplace_back(tile2); +_queue.erase(_queue.begin() + i); +found = true; +break; +} +} + +i += !found; +} + +if (tiles.size() == 1) +{ +msg = tiles[0].serialize("tile"); +return Payload(msg.data(), msg.data() + msg.size()); +} + +auto tileCombined = TileCombined::create(tiles).serialize("tilecombine"); +Log::trace() << "MessageQueue res: " << tileCombined << Log::end; +return Payload(tileCombined.data(), tileCombined.data() + tileCombined.size()); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/loolwsd/MessageQueue.hpp b/loolwsd/MessageQueue.hpp index f1b14b2..4d1efba 100644 --- a/loolwsd/MessageQueue.hpp +++ b/loolwsd/MessageQueue.hpp @@
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp |2 +- 1 file changed, 1 insertion(+), 1 deletion(-) New commits: commit 3b2055a0a880e79f9a4c3dec0fa2c91cbc9c07ce Author: Ashod Nakashian Date: Tue Sep 20 07:56:06 2016 -0400 loolwsd: remove the callback descriptor after destroyView On destroyView Core must flush the events queue, otherwise by the next idle the descriptor will be gone and we'll be using freed memory. Change-Id: I6d3d8f9461bc156383a7294e9c65c535d79f2e7a Reviewed-on: https://gerrit.libreoffice.org/29088 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 4f1f448..a04945c 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -1002,8 +1002,8 @@ private: const auto viewId = session.getViewId(); _loKitDocument->setView(viewId); _loKitDocument->registerCallback(nullptr, nullptr); -_viewIdToCallbackDescr.erase(viewId); _loKitDocument->destroyView(viewId); +_viewIdToCallbackDescr.erase(viewId); Log::debug("Destroyed view " + std::to_string(viewId)); } ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 28 +++- 1 file changed, 11 insertions(+), 17 deletions(-) New commits: commit a9fbfe8d8ac802086844e307dff979a8e1436ba2 Author: Ashod Nakashian Date: Sat Sep 17 10:09:47 2016 -0400 loolwsd: remove queue thread from child socket handler Change-Id: Ib6b4890db1f331b2e2cdcfafb57366ff62e3a13d Reviewed-on: https://gerrit.libreoffice.org/29067 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 51c33f3..02919e6 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -57,7 +57,6 @@ #include "LibreOfficeKit.hpp" #include "Log.hpp" #include "Png.hpp" -#include "QueueHandler.hpp" #include "Rectangle.hpp" #include "TileDesc.hpp" #include "Unit.hpp" @@ -320,27 +319,21 @@ public: Log::debug("Thread started."); try { -auto queue = std::make_shared(); -QueueHandler handler(queue, _session, "kit_queue_" + _session->getId()); - -Thread queueHandlerThread; -queueHandlerThread.start(handler); -std::shared_ptr session = _session; - IoUtil::SocketProcessor(_ws, -[&queue](const std::vector& payload) +[this](const std::vector& payload) { -queue->put(payload); +if (!_session->handleInput(payload.data(), payload.size())) +{ +Log::info("Socket handler flagged for finishing."); +return false; +} + return true; }, -[&session]() { session->closeFrame(); }, -[&queueHandlerThread]() { return TerminationFlag || !queueHandlerThread.isRunning(); }); - -queue->clear(); -queue->put("eof"); -queueHandlerThread.join(); +[this]() { _session->closeFrame(); }, +[]() { return !!TerminationFlag; }); -if (session->isCloseFrame()) +if (_session->isCloseFrame()) { Log::trace("Normal close handshake."); _ws->shutdown(); @@ -1503,6 +1496,7 @@ void lokit_main(const std::string& childRoot, requestUrl += "&version=" + encodedVersionStr; free(versionInfo); } + HTTPRequest request(HTTPRequest::HTTP_GET, requestUrl); HTTPResponse response; auto ws = std::make_shared(cs, request, response); ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 25 ++--- 1 file changed, 22 insertions(+), 3 deletions(-) New commits: commit 23ef612970ff5e90ffc8da63f503170aef9a56be Author: Ashod Nakashian Date: Sat Sep 17 10:04:28 2016 -0400 loolwsd: ensure that the connection thread is running If the connection thread is not running when loading a document, the callback will drop events. This can happen when the thread is too slow to spawn, but we return from the createSession function and process client messages. This should solve the race where we lose notifications of other views when a new view is created. Change-Id: Ia79739889b2f01fbb374d48eb33620084f4ed1c1 Reviewed-on: https://gerrit.libreoffice.org/29063 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 252cfb3..51c33f3 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #define LOK_USE_UNSTABLE_API #include @@ -279,6 +280,16 @@ public: void start() { _thread.start(*this); + +// Busy-wait until we run. +// This is important to make sure we can process +// callbacks, which if we're late to start will +// be dropped. No need for async notification here. +constexpr auto delay = COMMAND_TIMEOUT_MS / 20; +for (auto i = 0; i < 20 && !isRunning(); ++i) +{ +std::this_thread::sleep_for(std::chrono::milliseconds(delay)); +} } bool isRunning() @@ -871,15 +882,23 @@ private: bool isFound = false; for (auto& it : pDescr->Doc->_connections) { -if (it.second->isRunning()) +auto session = it.second->getSession(); +if (session && session->getViewId() == pDescr->ViewId) { -auto session = it.second->getSession(); -if (session && session->getViewId() == pDescr->ViewId) +if (it.second->isRunning()) { isFound = true; auto pNotif = new CallbackNotification(session, nType, payload); pDescr->Doc->_callbackQueue.enqueueNotification(pNotif); } +else +{ +Log::error() << "Connection thread for session " << it.second->getSessionId() << " for view " + << pDescr->ViewId << " is not running. Dropping [" << LOKitHelper::kitCallbackTypeToString(nType) + << "] payload [" << payload << "]." << Log::end; +} + +break; } } ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 39 ++- 1 file changed, 18 insertions(+), 21 deletions(-) New commits: commit bad8ae9ed99879dbdac6cb37d425c922ba047d5b Author: Ashod Nakashian Date: Sat Sep 17 09:18:33 2016 -0400 loolwsd: one anonymous namespace per file is enough Change-Id: I12b4967a321de45fc50ad314775d01499b5edd80 Reviewed-on: https://gerrit.libreoffice.org/29061 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index d5d3fc9..252cfb3 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -231,6 +231,24 @@ namespace cap_free(caps); } +void symlinkPathToJail(const Path& jailPath, const std::string &loTemplate, + const std::string &loSubPath) +{ +Path symlinkSource(jailPath, Path(loTemplate.substr(1))); +File(symlinkSource.parent()).createDirectories(); + +std::string symlinkTarget; +for (auto i = 0; i < Path(loTemplate).depth(); i++) +symlinkTarget += "../"; +symlinkTarget += loSubPath; + +Log::debug("symlink(\"" + symlinkTarget + "\",\"" + symlinkSource.toString() + "\")"); +if (symlink(symlinkTarget.c_str(), symlinkSource.toString().c_str()) == -1) +{ +Log::syserror("symlink(\"" + symlinkTarget + "\",\"" + symlinkSource.toString() + "\") failed"); +throw Exception("symlink() failed"); +} +} } /// Connection thread with a client (via WSD). @@ -1292,27 +1310,6 @@ private: std::atomic_size_t _clientViews; }; -namespace { -void symlinkPathToJail(const Path& jailPath, const std::string &loTemplate, - const std::string &loSubPath) -{ -Path symlinkSource(jailPath, Path(loTemplate.substr(1))); -File(symlinkSource.parent()).createDirectories(); - -std::string symlinkTarget; -for (auto i = 0; i < Path(loTemplate).depth(); i++) -symlinkTarget += "../"; -symlinkTarget += loSubPath; - -Log::debug("symlink(\"" + symlinkTarget + "\",\"" + symlinkSource.toString() + "\")"); -if (symlink(symlinkTarget.c_str(), symlinkSource.toString().c_str()) == -1) -{ -Log::syserror("symlink(\"" + symlinkTarget + "\",\"" + symlinkSource.toString() + "\") failed"); -throw Exception("symlink() failed"); -} -} -} - void lokit_main(const std::string& childRoot, const std::string& sysTemplate, const std::string& loTemplate, ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 28 ++-- 1 file changed, 18 insertions(+), 10 deletions(-) New commits: commit ea274bcf6b94400cd4e3f13f1ac954ed5c24a36c Author: Miklos Vajna Date: Mon Sep 19 16:04:23 2016 +0200 Document::ViewCallback: don't fail on EMPTY cell cursor Change-Id: I67bee2a1f1332bfb82963e0fb3a0e761054f826e diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 29d84f4..d5d3fc9 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -814,12 +814,16 @@ private: nType == LOK_CALLBACK_CELL_CURSOR) { Poco::StringTokenizer tokens(payload, ",", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM); -auto cursorX = std::stoi(tokens[0]); -auto cursorY = std::stoi(tokens[1]); -auto cursorWidth = std::stoi(tokens[2]); -auto cursorHeight = std::stoi(tokens[3]); +// Payload may be 'EMPTY'. +if (tokens.count() == 4) +{ +auto cursorX = std::stoi(tokens[0]); +auto cursorY = std::stoi(tokens[1]); +auto cursorWidth = std::stoi(tokens[2]); +auto cursorHeight = std::stoi(tokens[3]); -pDescr->Doc->_tileQueue->updateCursorPosition(0, 0, cursorX, cursorY, cursorWidth, cursorHeight); +pDescr->Doc->_tileQueue->updateCursorPosition(0, 0, cursorX, cursorY, cursorWidth, cursorHeight); +} } else if (nType == LOK_CALLBACK_INVALIDATE_VIEW_CURSOR || nType == LOK_CALLBACK_CELL_VIEW_CURSOR) @@ -831,12 +835,16 @@ private: auto part = command->get("part").toString(); auto text = command->get("rectangle").toString(); Poco::StringTokenizer tokens(text, ",", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM); -auto cursorX = std::stoi(tokens[0]); -auto cursorY = std::stoi(tokens[1]); -auto cursorWidth = std::stoi(tokens[2]); -auto cursorHeight = std::stoi(tokens[3]); +// Payload may be 'EMPTY'. +if (tokens.count() == 4) +{ +auto cursorX = std::stoi(tokens[0]); +auto cursorY = std::stoi(tokens[1]); +auto cursorWidth = std::stoi(tokens[2]); +auto cursorHeight = std::stoi(tokens[3]); -pDescr->Doc->_tileQueue->updateCursorPosition(std::stoi(viewId), std::stoi(part), cursorX, cursorY, cursorWidth, cursorHeight); + pDescr->Doc->_tileQueue->updateCursorPosition(std::stoi(viewId), std::stoi(part), cursorX, cursorY, cursorWidth, cursorHeight); +} } // Forward to the same view only. ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp |5 - 1 file changed, 4 insertions(+), 1 deletion(-) New commits: commit 7fff96039118e29ebc125f65b94560332cd41355 Author: Ashod Nakashian Date: Mon Sep 19 00:20:02 2016 -0400 loolwsd: stop the tile-queue when exiting Change-Id: I49276c9639e8826d145a31eb476b41eb64baf88a Reviewed-on: https://gerrit.libreoffice.org/29009 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 74ef66b..29d84f4 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -426,6 +426,9 @@ public: _callbackQueue.wakeUpAll(); _callbackThread.join(); +_tileQueue->put("eof"); +_tilesThread.join(); + // Flag all connections to stop. for (auto aIterator : _connections) { @@ -1218,7 +1221,7 @@ private: try { -while (true) +while (!pThis->_stop) { const auto input = pThis->_tileQueue->get(); const std::string message(input.data(), input.size()); ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp loolwsd/LOOLWSD.cpp
loolwsd/LOOLKit.cpp |5 - loolwsd/LOOLWSD.cpp |8 2 files changed, 13 deletions(-) New commits: commit f0c09238ce0aa9772b182b1461af0a448332dda4 Author: Ashod Nakashian Date: Sat Sep 17 08:42:25 2016 -0400 loolwsd: fail fast rather than catch all Change-Id: Ib38924bf823315d211eb467d90f364fdc225ba2e Reviewed-on: https://gerrit.libreoffice.org/29005 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 2e3fdb9..74ef66b 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -289,7 +289,6 @@ public: Util::setThreadName("kit_ws_" + _sessionId); Log::debug("Thread started."); - try { auto queue = std::make_shared(); @@ -333,10 +332,6 @@ public: { Log::error(std::string("Connection::run: Exception: ") + exc.what()); } -catch (...) -{ -Log::error("Connection::run:: Unexpected exception"); -} Log::debug("Thread finished."); } diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index 57b996b..b496a1b 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -995,10 +995,6 @@ public: Log::error(std::string("ClientRequestHandler::handleRequest: Exception: ") + exc.what()); response.setStatusAndReason(HTTPResponse::HTTP_SERVICE_UNAVAILABLE); } -catch (...) -{ -Log::error("ClientRequestHandler::handleRequest:: Unexpected exception"); -} if (!responded) { @@ -1190,10 +1186,6 @@ public: { Log::error(std::string("PrisonerRequestHandler::handleRequest: Exception: ") + exc.what()); } -catch (...) -{ -Log::error("PrisonerRequestHandler::handleRequest:: Unexpected exception"); -} if (!jailId.empty()) { ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp |2 +- 1 file changed, 1 insertion(+), 1 deletion(-) New commits: commit 6006e2200151843efa983107e4039f9935e5906b Author: Miklos Vajna Date: Mon Sep 12 08:15:33 2016 +0200 LOOLKit: use std::move() in Document ctor Change-Id: I25aeb5285465385858180747f441a69b858c4fe6 diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 94d02ef..73ade5b 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -405,7 +405,7 @@ public: _jailId(jailId), _docKey(docKey), _url(url), -_queue(queue), +_queue(std::move(queue)), _ws(ws), _docPassword(""), _haveDocPassword(false), ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp loolwsd/MessageQueue.cpp
loolwsd/LOOLKit.cpp | 59 +++ loolwsd/MessageQueue.cpp | 43 ++ 2 files changed, 82 insertions(+), 20 deletions(-) New commits: commit 2663f9b63f986e97d092244ba793b56b347101cd Author: Ashod Nakashian Date: Thu Sep 1 16:45:04 2016 -0400 loolwsd: replace old tile requests with more recent ones A new queue with own thread now processes tile requests so we have a chance to cull backlogged tile requests that have since been invalidated. This reduces load on the server significantly, especially with multiple view at different zoom levels, and very fast typing. Change-Id: I6599939cd363dc71c30187f40d542aa37260dc56 Reviewed-on: https://gerrit.libreoffice.org/28607 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 0613aa7..b62754d 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #define LOK_USE_UNSTABLE_API #include @@ -396,18 +397,23 @@ public: Document(const std::shared_ptr& loKit, const std::string& jailId, const std::string& docKey, - const std::string& url) + const std::string& url, + std::shared_ptr queue, + const std::shared_ptr& ws) : _multiView(std::getenv("LOK_VIEW_CALLBACK")), _loKit(loKit), _jailId(jailId), _docKey(docKey), _url(url), +_queue(queue), +_ws(ws), _docPassword(""), _haveDocPassword(false), _isDocPasswordProtected(false), _docPasswordType(PasswordType::ToView), _stop(false), _isLoading(0), +_tilesThread(tilesThread, this), _clientViews(0) { Log::info("Document ctor for url [" + _url + "] on child [" + _jailId + @@ -1188,6 +1194,44 @@ private: Log::debug("Thread finished."); } +static void tilesThread(Document* pThis) +{ +Util::setThreadName("tile_renderer"); + +Log::debug("Thread started."); + +try +{ +while (true) +{ +const auto input = pThis->_queue->get(); +const std::string message(input.data(), input.size()); +StringTokenizer tokens(message, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM); + +if (tokens[0] == "eof") +{ +Log::info("Received EOF. Finishing."); +break; +} + +if (tokens[0] == "tile") +{ +pThis->renderTile(tokens, pThis->_ws); +} +else if (tokens[0] == "tilecombine") +{ +pThis->renderCombinedTiles(tokens, pThis->_ws); +} +} +} +catch (const std::exception& exc) +{ +Log::error(std::string("QueueHandler::run: Exception: ") + exc.what()); +} + +Log::debug("Thread finished."); +} + private: const bool _multiView; @@ -1199,6 +1243,8 @@ private: std::string _renderOpts; std::shared_ptr _loKitDocument; +std::shared_ptr _queue; +std::shared_ptr _ws; // Document password provided std::string _docPassword; @@ -1216,6 +1262,7 @@ private: std::map> _viewIdToCallbackDescr; std::map> _connections; Poco::Thread _callbackThread; +std::thread _tilesThread; Poco::NotificationQueue _callbackQueue; std::atomic_size_t _clientViews; }; @@ -1420,9 +1467,11 @@ void lokit_main(const std::string& childRoot, auto ws = std::make_shared(cs, request, response); ws->setReceiveTimeout(0); +auto queue = std::make_shared(); + const std::string socketName = "ChildControllerWS"; IoUtil::SocketProcessor(ws, -[&socketName, &ws, &document, &loKit](const std::vector& data) +[&socketName, &ws, &document, &loKit, &queue](const std::vector& data) { std::string message(data.data(), data.size()); @@ -1449,7 +1498,7 @@ void lokit_main(const std::string& childRoot, if (!document) { -document = std::make_shared(loKit, jailId, docKey, url); +document = std::make_shared(loKit, jailId, docKey, url, queue, ws); } // Validate and create session. @@ -1463,7 +1512,7 @@ void lokit_main(const std::string& childRoot, { if (document) { -document->renderTile(tokens, ws); +queue->put(message); }
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 28 +--- 1 file changed, 17 insertions(+), 11 deletions(-) New commits: commit f4c0a87991cb574ea86ea75d259cdc7c9a1a0eb9 Author: Ashod Nakashian Date: Thu Sep 1 08:31:40 2016 -0400 Revert "loolwsd: remove queue thread from child socket handler" This reverts commit a30526c87ea01026f6ff3f07671ddfc614aebc5e. Change-Id: Idcbf2a6c4e228a5fb6a890e8cdd58b6137295666 Reviewed-on: https://gerrit.libreoffice.org/28596 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index d3c98b7..84a02f2 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -55,6 +55,7 @@ #include "LibreOfficeKit.hpp" #include "Log.hpp" #include "Png.hpp" +#include "QueueHandler.hpp" #include "Rectangle.hpp" #include "TileDesc.hpp" #include "Unit.hpp" @@ -291,21 +292,27 @@ public: try { +auto queue = std::make_shared(); +QueueHandler handler(queue, _session, "kit_queue_" + _session->getId()); + +Thread queueHandlerThread; +queueHandlerThread.start(handler); +std::shared_ptr session = _session; + IoUtil::SocketProcessor(_ws, -[this](const std::vector& payload) +[&queue](const std::vector& payload) { -if (!_session->handleInput(payload.data(), payload.size())) -{ -Log::info("Socket handler flagged for finishing."); -return false; -} - +queue->put(payload); return true; }, -[this]() { _session->closeFrame(); }, -[]() { return !!TerminationFlag; }); +[&session]() { session->closeFrame(); }, +[&queueHandlerThread]() { return TerminationFlag || !queueHandlerThread.isRunning(); }); + +queue->clear(); +queue->put("eof"); +queueHandlerThread.join(); -if (_session->isCloseFrame()) +if (session->isCloseFrame()) { Log::trace("Normal close handshake."); _ws->shutdown(); @@ -1410,7 +1417,6 @@ void lokit_main(const std::string& childRoot, requestUrl += "&version=" + encodedVersionStr; free(versionInfo); } - HTTPRequest request(HTTPRequest::HTTP_GET, requestUrl); HTTPResponse response; auto ws = std::make_shared(cs, request, response); ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 14 +- 1 file changed, 13 insertions(+), 1 deletion(-) New commits: commit fad6715f7d69b3e551deca566d72cfd1b7302d50 Author: Ashod Nakashian Date: Tue Aug 30 19:23:51 2016 -0400 loolwsd: guard against processing commands before fully loading Change-Id: Iac915074728f616d81b05558b886998855326a2e Reviewed-on: https://gerrit.libreoffice.org/28525 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index a2ff02e..d3c98b7 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -705,6 +705,12 @@ public: } std::unique_lock lock(_loKitDocument->getLock()); +if (_loKitDocument->getViews() <= 0) +{ +Log::error("Tile rendering requested without views."); +return; +} + Timestamp timestamp; _loKitDocument->paintPartTile(pixmap.data(), tileCombined.getPart(), pixmapWidth, pixmapHeight, @@ -998,14 +1004,15 @@ private: auto session = it->second->getSession(); int viewId = 0; +std::unique_lock lockLokDoc; if (!_loKitDocument) { // This is the first time we are loading the document Log::info("Loading new document from URI: [" + uri + "] for session [" + sessionId + "]."); - auto lock(_loKit->getLock()); + if (LIBREOFFICEKIT_HAS(_loKit->get(), registerCallback)) { _loKit->get()->pClass->registerCallback(_loKit->get(), GlobalCallback, this); @@ -1023,6 +1030,8 @@ private: Log::debug("Calling lokit::documentLoad."); _loKitDocument = _loKit->documentLoad(uri.c_str()); Log::debug("Returned lokit::documentLoad."); +auto l(_loKitDocument->getLock()); +lockLokDoc.swap(l); if (!_loKitDocument || !_loKitDocument->get()) { @@ -1058,6 +1067,9 @@ private: } else { +auto l(_loKitDocument->getLock()); +lockLokDoc.swap(l); + // Check if this document requires password if (_isDocPasswordProtected) { ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp loolwsd/LOOLWSD.cpp
loolwsd/LOOLKit.cpp |5 + loolwsd/LOOLWSD.cpp |7 --- 2 files changed, 9 insertions(+), 3 deletions(-) New commits: commit a674fc7e8fda162b7e84c75902d36cb9b9030650 Author: Ashod Nakashian Date: Tue Aug 30 18:21:50 2016 -0400 loolwsd: logs and formatting Change-Id: Ic3ec268cdc1962814654c7be676da62375494f66 Reviewed-on: https://gerrit.libreoffice.org/28524 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 944a029..a2ff02e 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -1467,6 +1467,7 @@ void lokit_main(const std::string& childRoot, } else if (document && document->canDiscard()) { +Log::info("Last session discarded. Terminating."); TerminationFlag = true; } else @@ -1480,7 +1481,11 @@ void lokit_main(const std::string& childRoot, [&document]() { if (document && document->canDiscard()) +{ +Log::info("Last session discarded. Terminating."); TerminationFlag = true; +} + return TerminationFlag.load(); }); diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index 5749f9c..0988b4c 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -911,18 +911,18 @@ public: // http://server/hosting/discovery responded = handleGetWOPIDiscovery(request, response); } -// All post requests have url prefix, lool else if (!(request.find("Upgrade") != request.end() && Poco::icompare(request["Upgrade"], "websocket") == 0) && reqPathSegs.size() > 0 && reqPathSegs[0] == "lool") { +// All post requests have url prefix 'lool'. responded = handlePostRequest(request, response, id); } else if (reqPathSegs.size() > 2 && reqPathSegs[0] == "lool" && reqPathSegs[1] == "ws") { auto ws = std::make_shared(request, response); +responded = true; // After upgrading to WS we should not set HTTP response. try { -responded = true; // After upgrading to WS we should not set HTTP response. handleGetRequest(request, ws, id); } catch (const WebSocketErrorMessageException& exc) @@ -1868,9 +1868,10 @@ int LOOLWSD::main(const std::vector& /*args*/) else if (pid < 0) { Log::syserror("waitpid failed."); -// No child processes if (errno == ECHILD) { +// No child processes. +Log::error("No Forkit instance. Terminating."); TerminationFlag = true; continue; } ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp |3 +++ 1 file changed, 3 insertions(+) New commits: commit d8a38f58592dd02b5dcfd88a7d266f1fb5239eb0 Author: Ashod Nakashian Date: Tue Aug 30 14:30:24 2016 -0400 loolwsd: startup logs Change-Id: I90e7debbe881eafc9d65f4ff6a5d5f39d8277c0e Reviewed-on: https://gerrit.libreoffice.org/28519 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index f81adae..944a029 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -1535,6 +1535,7 @@ bool globalPreinit(const std::string &loTemplate) void *handle; if (File(libMerged).exists()) { +Log::trace("dlopen(" + libMerged + ", RTLD_GLOBAL|RTLD_NOW)"); handle = dlopen(libMerged.c_str(), RTLD_GLOBAL|RTLD_NOW); if (!handle) { @@ -1547,6 +1548,7 @@ bool globalPreinit(const std::string &loTemplate) { if (File(libSofficeapp).exists()) { +Log::trace("dlopen(" + libSofficeapp + ", RTLD_GLOBAL|RTLD_NOW)"); handle = dlopen(libSofficeapp.c_str(), RTLD_GLOBAL|RTLD_NOW); if (!handle) { @@ -1569,6 +1571,7 @@ bool globalPreinit(const std::string &loTemplate) return false; } +Log::trace("lok_preinit(" + loTemplate + "/program\", \"file:///user\")"); if (preInit((loTemplate + "/program").c_str(), "file:///user") != 0) { Log::error("lok_preinit() in " + loadedLibrary + " failed"); ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp |8 1 file changed, 4 insertions(+), 4 deletions(-) New commits: commit 38a84d2c90554acac157d55ea1e7b8f7e490f355 Author: Ashod Nakashian Date: Tue Aug 30 10:35:58 2016 -0400 loolwsd: log the tile version after rendering Change-Id: Id0d532bbf2d836a31ba90f1a47664bd7261a1779 Reviewed-on: https://gerrit.libreoffice.org/28517 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index ac72c4d..f81adae 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -642,7 +642,7 @@ public: tile.getTilePosX(), tile.getTilePosY(), tile.getTileWidth(), tile.getTileHeight()); Log::trace() << "paintTile at (" << tile.getPart() << ',' << tile.getTilePosX() << ',' << tile.getTilePosY() - << ") rendered in " << (timestamp.elapsed()/1000.) << " ms" << Log::end; + << ") " << "ver: " << tile.getVersion() << " rendered in " << (timestamp.elapsed()/1000.) << " ms" << Log::end; const auto mode = static_cast(_loKitDocument->getTileMode()); if (!png::encodeBufferToPNG(pixmap.data(), tile.getWidth(), tile.getHeight(), output, mode)) @@ -710,9 +710,9 @@ public: pixmapWidth, pixmapHeight, renderArea.getLeft(), renderArea.getTop(), renderArea.getWidth(), renderArea.getHeight()); -Log::debug() << "paintTile (combined) called, tile at [" << renderArea.getLeft() << ", " << renderArea.getTop() << "]" - << " (" << renderArea.getWidth() << ", " << renderArea.getHeight() << ") rendered in " - << double(timestamp.elapsed())/1000 << " ms." << Log::end; +Log::debug() << "paintTile (combined) at (" << renderArea.getLeft() << ", " << renderArea.getTop() << "), (" + << renderArea.getWidth() << ", " << renderArea.getHeight() << ") ver: " << tileCombined.getVersion() + << " rendered in " << (timestamp.elapsed()/1000.) << " ms." << Log::end; const auto mode = static_cast(_loKitDocument->getTileMode()); std::vector output; ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp |2 +- 1 file changed, 1 insertion(+), 1 deletion(-) New commits: commit 7e3225dcebd437bd7e2d59c64a58d5f246474272 Author: Miklos Vajna Date: Mon Aug 29 09:23:08 2016 +0200 LOOLKit: avoid unnecessary copy-initialization Change-Id: I14a4bb7803676173ac164ff8bd7e9eeaa6031f75 diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 0316835..0d249a7 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -883,7 +883,7 @@ private: void onUnload(const ChildSession& session) override { -const auto sessionId = session.getId(); +const auto& sessionId = session.getId(); Log::info("Unloading [" + sessionId + "]."); // Broadcast the demise and removal of session. ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp |2 +- 1 file changed, 1 insertion(+), 1 deletion(-) New commits: commit ec6ddf91baa3ea7281237ec508fde92306b91a3b Author: Pranav Kant Date: Thu Aug 25 21:10:47 2016 +0530 loolwsd: Send viewId to clients, not sessionId diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 897f033..b73779e 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -895,7 +895,7 @@ private: for (const auto& pair : _connections) { assert(sessionId != pair.second->getSessionId() && "Unloading connection still lingering."); -pair.second->getSession()->sendTextFrame("remview: " + sessionId); +pair.second->getSession()->sendTextFrame("remview: " + std::to_string(session.getViewId())); } if (_loKitDocument == nullptr) ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 36 +--- 1 file changed, 29 insertions(+), 7 deletions(-) New commits: commit 39a1fd0addcd2f4d93c0947b070ba175a9f89ca6 Author: Ashod Nakashian Date: Sat Aug 20 09:10:30 2016 -0400 loolwsd: Document unloading doesn't hold Document lock anymore Change-Id: I4be051b9a24a7a971211e6f7159d959c5f504c0e Reviewed-on: https://gerrit.libreoffice.org/28296 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index f21268b..806201c 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -791,6 +791,8 @@ private: << "] [" << LOKitHelper::kitCallbackTypeToString(nType) << "] [" << payload << "]." << Log::end; +std::unique_lock lock(pDescr->Doc->_mutex); + // Forward to the same view only. // Demultiplexing is done by Core. // TODO: replace with a map to be faster. @@ -885,27 +887,47 @@ private: Log::info("Unloading [" + sessionId + "]."); const unsigned intSessionId = Util::decodeId(sessionId); -std::unique_lock lock(_mutex); - -const auto it = _connections.find(intSessionId); -if (it == _connections.end() || !it->second || !_loKitDocument || !_loKitDocument->get()) +if (_loKitDocument == nullptr) { -// Nothing to do. -Log::error("No [" + sessionId + "] session!"); +Log::error("Unloading session [" + sessionId + "] without loKitDocument."); return; } +// Find this session connection. +int sessionViewId = -1; +{ +std::unique_lock lock(_mutex); + +const auto it = _connections.find(intSessionId); +if (it == _connections.end() || !it->second || !it->second->getSession()) +{ +Log::error("Session [" + sessionId + "] not found to unload."); +return; +} + +sessionViewId = it->second->getSession()->getViewId(); +} + --_clientViews; Log::info("Session " + sessionId + " is unloading. " + std::to_string(_clientViews) + " view" + (_clientViews != 1 ? "s" : "") + " remain."); -if (_multiView && _loKitDocument) +if (_multiView) { Log::info() << "Document [" << _url << "] session [" << sessionId << "] unloaded, leaving " << _clientViews << " views." << Log::end; +std::unique_lock lock(_loKitDocument->getLock()); + const auto viewId = _loKitDocument->getView(); +if (viewId != sessionViewId) +{ +Log::error() << "Unloading view [" << sessionViewId + << "] from view [" << viewId << "]." << Log::end; +return; +} + _viewIdToCallbackDescr.erase(viewId); _loKitDocument->registerCallback(nullptr, nullptr); _loKitDocument->destroyView(viewId); ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp |6 ++ 1 file changed, 6 insertions(+) New commits: commit 119d2c862c5a94b342ea46d929f84fbfd05d5912 Author: Ashod Nakashian Date: Thu Aug 18 23:13:21 2016 -0400 loolwsd: don't render tiles when no views exists Change-Id: Ic7bc72384372961752dc68671b0dd20f592cb669 Reviewed-on: https://gerrit.libreoffice.org/28292 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 9e6b6d5..8123c7b 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -626,6 +626,12 @@ public: return; } +if (_loKitDocument->getViews() <= 0) +{ +Log::error("Tile rendering requested without views."); +return; +} + Timestamp timestamp; _loKitDocument->paintPartTile(pixmap.data(), tile.getPart(), tile.getWidth(), tile.getHeight(), ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp |2 +- 1 file changed, 1 insertion(+), 1 deletion(-) New commits: commit 955a2d5577299c8db58668f1dc4f6a522ce612c5 Author: Miklos Vajna Date: Mon Aug 15 09:47:31 2016 +0200 LOOLKit: fix -Werror,-Winconsistent-missing-override Change-Id: Ia4ffbb32730880c188f9d9bf9b14d3e3daebc272 diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 69bc462..4777922 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -1040,7 +1040,7 @@ private: return _loKitDocument; } -void run() +void run() override { Util::setThreadName("kit_callback"); ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 26 +++--- 1 file changed, 15 insertions(+), 11 deletions(-) New commits: commit f64a18d5202e4c2c9a7f34f25b8b7728931693ec Author: Ashod Nakashian Date: Sun Aug 14 11:54:14 2016 -0400 loolwsd: corrected ChildSession and connection cleanup ChildSession and Connection are run their own thread and their destruction depends on the connection, which of course is completely asynchronous. This change fires the destruction of the ChildSession, which unloads the view, without destroying the connection. The latter is cleaned up when purgeSessions() is invoked. Change-Id: I341bfdbdd4b37338d1813ec707a51aeb3be59497 Reviewed-on: https://gerrit.libreoffice.org/28130 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 4c9d545..a05c7e1 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -232,17 +232,18 @@ class Connection: public Runnable public: Connection(std::shared_ptr session, std::shared_ptr ws) : +_sessionId(session->getId()), _session(std::move(session)), _ws(std::move(ws)), _stop(false), _joined(false) { -Log::info("Connection ctor in child for " + _session->getId()); +Log::info("Connection ctor in child for " + _sessionId); } ~Connection() { -Log::info("~Connection dtor in child for " + _session->getId()); +Log::info("~Connection dtor in child for " + _sessionId); stop(); join(); } @@ -278,7 +279,7 @@ public: void run() override { -Util::setThreadName("kit_ws_" + _session->getId()); +Util::setThreadName("kit_ws_" + _sessionId); Log::debug("Thread started."); @@ -324,15 +325,18 @@ public: Log::error("Connection::run:: Unexpected exception"); } +// Release the session and unload view. +_session.reset(); Log::debug("Thread finished."); } private: +const std::string _sessionId; Thread _thread; std::shared_ptr _session; std::shared_ptr _ws; -std::atomic _stop; std::mutex _threadMutex; +std::atomic _stop; std::atomic _joined; }; @@ -862,22 +866,22 @@ private: void onUnload(const std::string& sessionId) { +Log::info("Unloading [" + sessionId + "]."); const unsigned intSessionId = Util::decodeId(sessionId); + +std::unique_lock lock(_mutex); + const auto it = _connections.find(intSessionId); if (it == _connections.end() || !it->second || !_loKitDocument) { // Nothing to do. +Log::error("No [" + sessionId + "] session!"); return; } -auto session = it->second->getSession(); -auto sessionLock = session->getLock(); -std::unique_lock lock(_mutex); - -Log::info("Session " + sessionId + " is unloading. Erasing connection."); -_connections.erase(it); --_clientViews; -Log::info("Session " + sessionId + " is unloading. " + std::to_string(_clientViews) + " views will remain."); +Log::info("Session " + sessionId + " is unloading. " + std::to_string(_clientViews) + + " view" + (_clientViews != 1 ? "s" : "") + " remain."); if (_multiView && _loKitDocument) { ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 37 +++-- 1 file changed, 15 insertions(+), 22 deletions(-) New commits: commit a30526c87ea01026f6ff3f07671ddfc614aebc5e Author: Ashod Nakashian Date: Sat Aug 13 19:32:59 2016 -0400 loolwsd: remove queue thread from child socket handler Change-Id: Ibcdd6146bf3fc20813520213b696079b793cf830 Reviewed-on: https://gerrit.libreoffice.org/28126 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 994e2a7..5a37d42 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -52,7 +52,6 @@ #include "LibreOfficeKit.hpp" #include "Log.hpp" #include "Png.hpp" -#include "QueueHandler.hpp" #include "Rectangle.hpp" #include "TileDesc.hpp" #include "Unit.hpp" @@ -284,27 +283,21 @@ public: try { -auto queue = std::make_shared(); -QueueHandler handler(queue, _session, "kit_queue_" + _session->getId()); - -Thread queueHandlerThread; -queueHandlerThread.start(handler); -std::shared_ptr session = _session; - IoUtil::SocketProcessor(_ws, -[&queue](const std::vector& payload) +[this](const std::vector& payload) { -queue->put(payload); +if (!_session->handleInput(payload.data(), payload.size())) +{ +Log::info("Socket handler flagged for finishing."); +return false; +} + return true; }, -[&session]() { session->closeFrame(); }, -[&queueHandlerThread]() { return TerminationFlag || !queueHandlerThread.isRunning(); }); - -queue->clear(); -queue->put("eof"); -queueHandlerThread.join(); +[this]() { _session->closeFrame(); }, +[]() { return !!TerminationFlag; }); -if (session->isCloseFrame()) +if (_session->isCloseFrame()) { Log::trace("Normal close handshake."); _ws->shutdown(); @@ -760,15 +753,15 @@ private: static void ViewCallback(const int nType, const char* pPayload, void* pData) { -const std::string payload = pPayload ? pPayload : "(nil)"; -Log::trace() << "Document::ViewCallback " - << LOKitHelper::kitCallbackTypeToString(nType) - << " [" << payload << "]." << Log::end; - CallbackDescriptor* pDescr = reinterpret_cast(pData); assert(pDescr && "Null callback data."); assert(pDescr->Doc && "Null Document instance."); +const std::string payload = pPayload ? pPayload : "(nil)"; +Log::trace() << "Document::ViewCallback [" << pDescr->ViewId + << "] [" << LOKitHelper::kitCallbackTypeToString(nType) + << "] [" << payload << "]." << Log::end; + // Forward to the same view only. // Demultiplexing is done by Core. // TODO: replace with a map to be faster. ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 25 ++--- 1 file changed, 22 insertions(+), 3 deletions(-) New commits: commit 5a20ae67baaf95d5f63373b4f429fcdb320b9649 Author: Ashod Nakashian Date: Fri Aug 12 18:42:47 2016 -0400 loolwsd: parse the ViewId of event payloads to dispatch Change-Id: I70e603c7f9d5d63e6ca0c3fb0364310112bc03c0 Reviewed-on: https://gerrit.libreoffice.org/28121 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index bb0a42a..50f100a 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #define LOK_USE_UNSTABLE_API #include @@ -338,6 +339,9 @@ private: std::atomic _joined; }; +/// Regex to parse the ViewId from json. +static std::regex ViewIdRegex("\"viewId\"\\s*:\\s*\"(\\d*)\""); + /// A document container. /// Owns LOKitDocument instance and connections. /// Manages the lifetime of a document. @@ -739,7 +743,18 @@ private: return; } -const auto viewId = self->_loKitDocument->getView(); +// We can't invoke loKitDocument here as that could deadlock. +// We have to parse the message to get the target view. +// We can do it here once at the expense of the lok thread, or, +// dispatch swiftly and prase multiple times in each session. +int viewId = -1; +std::smatch match; +if (std::regex_search(payload.begin(), payload.end(), match, ViewIdRegex) && +match.length() > 1) +{ +const auto strViewId = match[1].str(); +viewId = std::stoi(strViewId); +} // Forward to the same view only. for (auto& it: self->_connections) @@ -747,9 +762,13 @@ private: if (it.second->isRunning()) { auto session = it.second->getSession(); -if (session && session->getViewId() == viewId) +if (session) { -session->loKitCallback(nType, pPayload); +if (viewId < 0 || session->getViewId() == viewId) +{ +// Broadcast if not view-specific. +session->loKitCallback(nType, payload); +} } } } ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 40 +--- 1 file changed, 37 insertions(+), 3 deletions(-) New commits: commit dafa5d078de76aab9aaf8f0990b066fe476805a3 Author: Ashod Nakashian Date: Thu Aug 11 20:09:55 2016 -0400 loolwsd: split out per-view LOK callback from default Change-Id: I01c0bb14cabbbe06bc790920d0f74d0f106bbbde Reviewed-on: https://gerrit.libreoffice.org/28118 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 7a7b545..6a54fd1 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -717,9 +717,41 @@ public: private: -static void ViewCallback(int , const char* , void* ) +static void ViewCallback(const int nType, const char* pPayload, void* pData) { -//TODO: Delegate the callback. +Log::trace() << "Document::ViewCallback " + << LOKitHelper::kitCallbackTypeToString(nType) + << " [" << (pPayload ? pPayload : "") << "]." << Log::end; +Document* self = reinterpret_cast(pData); +if (self == nullptr) +{ +return; +} + +std::unique_lock lock(self->_mutex); + +if (nType == LOK_CALLBACK_DOCUMENT_PASSWORD_TO_MODIFY || +nType == LOK_CALLBACK_DOCUMENT_PASSWORD) +{ +// Mark the document password type. +self->setDocumentPassword(nType); +return; +} + +const auto viewId = self->_loKitDocument->getView(); + +// Forward to the same view only. +for (auto& it: self->_connections) +{ +if (it.second->isRunning()) +{ +auto session = it.second->getSession(); +if (session && session->getViewId() == viewId) +{ +session->loKitCallback(nType, pPayload); +} +} +} } static void DocumentCallback(const int nType, const char* pPayload, void* pData) @@ -848,6 +880,7 @@ private: } auto session = it->second->getSession(); +auto& callback = _multiView ? ViewCallback : DocumentCallback; if (!_loKitDocument) { @@ -858,6 +891,7 @@ private: auto lock(_loKit->getLock()); if (LIBREOFFICEKIT_HAS(_loKit->get(), registerCallback)) { +//TODO: Use GlobalCallback for Password and statusindicator. _loKit->get()->pClass->registerCallback(_loKit->get(), DocumentCallback, this); const auto flags = LOK_FEATURE_DOCUMENT_PASSWORD | LOK_FEATURE_DOCUMENT_PASSWORD_TO_MODIFY; @@ -943,7 +977,7 @@ private: // registerCallback(), as the previous creates a new view in Impress. _loKitDocument->initializeForRendering(_renderOpts.c_str()); -_loKitDocument->registerCallback(DocumentCallback, this); +_loKitDocument->registerCallback(callback, this); return _loKitDocument; } ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp |4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) New commits: commit 3f2165b31a76a84996487bc03911568c031661f1 Author: Miklos Vajna Date: Wed Aug 10 09:23:16 2016 +0200 LOOLKit: avoid multiplication at int precision When the result is already stored as long. Change-Id: If5ef932c08c212432b5aca2a2300908e521f4ce8 diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 74c32c9..c59aade 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -673,8 +673,8 @@ public: size_t tileIndex = 0; for (Util::Rectangle& tileRect : tileRecs) { -const int positionX = (tileRect.getLeft() - renderArea.getLeft()) / tileCombined.getTileWidth(); -const int positionY = (tileRect.getTop() - renderArea.getTop()) / tileCombined.getTileHeight(); +const size_t positionX = (tileRect.getLeft() - renderArea.getLeft()) / tileCombined.getTileWidth(); +const size_t positionY = (tileRect.getTop() - renderArea.getTop()) / tileCombined.getTileHeight(); const auto oldSize = output.size(); const auto pixelWidth = tileCombined.getWidth(); ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp loolwsd/LOOLWSD.cpp
loolwsd/LOOLKit.cpp |1 + loolwsd/LOOLWSD.cpp |4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) New commits: commit 1300b412fbeb00e465b689ee57a5a321cc7c4740 Author: Ashod Nakashian Date: Wed Jul 27 10:57:08 2016 -0400 loolwsd: comments Change-Id: I57ba646df6ceb24d4f101a5539c979e77130cfc9 Reviewed-on: https://gerrit.libreoffice.org/27589 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index bde9f50..e3b5ec1 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -743,6 +743,7 @@ private: return; } +// Broadcast to all clients. for (auto& it: self->_connections) { if (it.second->isRunning()) diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index f7b7bce..daa8946 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -683,13 +683,13 @@ private: // Wait until the client has connected with a prison socket. waitBridgeCompleted(session); -// Now the bridge beetween the client and kit process is connected -// Let messages flow +// Now the bridge beetween the client and kit process is connected status = "statusindicator: ready"; Log::trace("Sending to Client [" + status + "]."); ws->sendFrame(status.data(), (int) status.size()); +// Let messages flow QueueHandler handler(queue, session, "wsd_queue_" + session->getId()); Thread queueHandlerThread; queueHandlerThread.start(handler); ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 12 ++-- 1 file changed, 6 insertions(+), 6 deletions(-) New commits: commit 97207e21caab0bfc622db40117af5904cffdca1a Author: Miklos Vajna Date: Wed Jul 20 09:53:32 2016 +0200 LOOLKit: avoid loss of precision '4 * pixmapWidth * pixmapHeight' was calculated using int precision, and then (implicitly) casted to long. diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 569fb2b..bde9f50 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -228,8 +228,8 @@ class Connection: public Runnable public: Connection(std::shared_ptr session, std::shared_ptr ws) : -_session(session), -_ws(ws), +_session(std::move(session)), +_ws(std::move(ws)), _stop(false), _joined(false) { @@ -643,10 +643,10 @@ public: tileRecs.push_back(rectangle); } -const int tilesByX = renderArea.getWidth() / tileCombined.getTileWidth(); -const int tilesByY = renderArea.getHeight() / tileCombined.getTileHeight(); -const int pixmapWidth = tilesByX * tileCombined.getWidth(); -const int pixmapHeight = tilesByY * tileCombined.getHeight(); +const size_t tilesByX = renderArea.getWidth() / tileCombined.getTileWidth(); +const size_t tilesByY = renderArea.getHeight() / tileCombined.getTileHeight(); +const size_t pixmapWidth = tilesByX * tileCombined.getWidth(); +const size_t pixmapHeight = tilesByY * tileCombined.getHeight(); const size_t pixmapSize = 4 * pixmapWidth * pixmapHeight; std::vector pixmap(pixmapSize, 0); ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 20 ++-- 1 file changed, 10 insertions(+), 10 deletions(-) New commits: commit 78687a2b18d8de90db662796c16ad7670c2793ac Author: Miklos Vajna Date: Tue Jul 19 11:11:58 2016 +0200 LOOLKit: be explicit when testing for non-equality So that it's obvious that strcmp() is not just a mistyped !strcmp(). diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 1c02554..569fb2b 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -94,17 +94,17 @@ namespace { case COPY_NO_USR: // bind mounted. -return strcmp(path,"usr"); +return strcmp(path,"usr") != 0; case COPY_LO: return -strcmp(path, "program/wizards") && -strcmp(path, "sdk") && -strcmp(path, "share/basic") && -strcmp(path, "share/gallery") && -strcmp(path, "share/Scripts") && -strcmp(path, "share/template") && -strcmp(path, "share/config/wizard") && -strcmp(path, "share/config/wizard"); +strcmp(path, "program/wizards") != 0 && +strcmp(path, "sdk") != 0 && +strcmp(path, "share/basic") != 0 && +strcmp(path, "share/gallery") != 0 && +strcmp(path, "share/Scripts") != 0 && +strcmp(path, "share/template") != 0 && +strcmp(path, "share/config/wizard") != 0 && +strcmp(path, "share/config/wizard") != 0; default: // COPY_ALL return true; } @@ -1050,7 +1050,7 @@ void lokit_main(const std::string& childRoot, char *resolved = realpath(loTemplate.c_str(), NULL); if (resolved) { -if (strcmp(loTemplate.c_str(), resolved)) +if (strcmp(loTemplate.c_str(), resolved) != 0) symlinkPathToJail(jailPath, std::string(resolved), loSubPath); free (resolved); } ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp |2 +- 1 file changed, 1 insertion(+), 1 deletion(-) New commits: commit c005f765bfefb1a7f9f1936c140e7ea4ba69ff2b Author: Ashod Nakashian Date: Sun May 29 20:18:17 2016 -0400 loolwsd: reuse the same callback for now Change-Id: I0f5ff42ed8c3ab422909d185089bfc31d5bb298b Reviewed-on: https://gerrit.libreoffice.org/25663 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index b462076..074a263 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -906,7 +906,7 @@ private: Log::info("Loading view to document from URI: [" + uri + "] for session [" + sessionId + "]."); const auto viewId = _loKitDocument->createView(); -_loKitDocument->registerCallback(ViewCallback, reinterpret_cast(intSessionId)); +_loKitDocument->registerCallback(DocumentCallback, this); Log::info() << "Document [" << _url << "] view [" << viewId << "] loaded, leaving " ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp |2 -- 1 file changed, 2 deletions(-) New commits: commit 335611b0ff2bcbe2341d9718f49c8c9139c5c4b5 Author: Ashod Nakashian Date: Sun May 29 18:31:56 2016 -0400 loolwsd: don't unlock too soon Since rendering moved to centralized WSD<->Kit processing, it runs on a different thread than those processing the communication between ClientSession and ChildSession. This introduces a new race between events and tile rendering. The shared ChildSession lock prevents this race such that no events are processed while a tile is rendered and, more importantly, response is prepared and sent back. That preparation could be lengthy due to png compression. The typical race happens when two keystrokes are entered in quick succession such that the same tile is invalidated while it's rendered. If the invalidation is processed in parallel to rendering, it will find no cached image to remove. It will reach the client, who will request a new tile. Meanwhile, the first tile is rendered and cached. By the time the second request arrives we have a cache hit, albeit on an outdated tile, missing the second character. By locking until the tile response is sent we ensure that the invalidate event will follow it, and by then the image will have been cached. The invalidation then removes the cached image and the second tile request is forced to place a new tile render request. There is some inefficiency, it would seem, but that is not really true, as Core is really sequential anyway and we shouldn't process events in parallel in the first place. Change-Id: Id8170a41a7e69bca6ac8b520029b7cdb2d96c880 Reviewed-on: https://gerrit.libreoffice.org/25662 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 626435a..b462076 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -597,7 +597,6 @@ public: Log::trace() << "paintTile at (" << tile.getPart() << ',' << tile.getTilePosX() << ',' << tile.getTilePosY() << ") rendered in " << (timestamp.elapsed()/1000.) << " ms" << Log::end; const auto mode = static_cast(_loKitDocument->getTileMode()); -lock.unlock(); if (!png::encodeBufferToPNG(pixmap.data(), tile.getWidth(), tile.getHeight(), output, mode)) { @@ -667,7 +666,6 @@ public: << " (" << renderArea.getWidth() << ", " << renderArea.getHeight() << ") rendered in " << double(timestamp.elapsed())/1000 << " ms." << Log::end; const auto mode = static_cast(_loKitDocument->getTileMode()); -lock.unlock(); std::vector output; output.reserve(pixmapWidth * pixmapHeight * 4); ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 33 ++--- 1 file changed, 18 insertions(+), 15 deletions(-) New commits: commit 1f8f5da8854093230a3309ace0f434cb8985e4b1 Author: Ashod Nakashian Date: Sun May 22 15:17:13 2016 -0400 loolwsd: localize lock around painting tiles Change-Id: I727f719fc22643d32d9fb5e4a89048a9991bb250 Reviewed-on: https://gerrit.libreoffice.org/25343 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index f594fa8..626435a 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -566,14 +566,6 @@ public: { auto tile = TileDesc::parse(tokens); -std::unique_lock lock(ChildSession::getLock()); - -if (!_loKitDocument) -{ -Log::error("Tile rendering requested before loading document."); -return; -} - // Send back the request with all optional parameters given in the request. const auto tileMsg = tile.serialize("tile:"); #if ENABLE_DEBUG @@ -590,6 +582,13 @@ public: std::vector pixmap; pixmap.resize(output.capacity()); +std::unique_lock lock(ChildSession::getLock()); +if (!_loKitDocument) +{ +Log::error("Tile rendering requested before loading document."); +return; +} + Timestamp timestamp; _loKitDocument->paintPartTile(pixmap.data(), tile.getPart(), tile.getWidth(), tile.getHeight(), @@ -597,8 +596,9 @@ public: tile.getTileWidth(), tile.getTileHeight()); Log::trace() << "paintTile at (" << tile.getPart() << ',' << tile.getTilePosX() << ',' << tile.getTilePosY() << ") rendered in " << (timestamp.elapsed()/1000.) << " ms" << Log::end; - const auto mode = static_cast(_loKitDocument->getTileMode()); +lock.unlock(); + if (!png::encodeBufferToPNG(pixmap.data(), tile.getWidth(), tile.getHeight(), output, mode)) { //FIXME: Return error. @@ -646,29 +646,32 @@ public: const int tilesByX = renderArea.getWidth() / tileCombined.getTileWidth(); const int tilesByY = renderArea.getHeight() / tileCombined.getTileHeight(); - const int pixmapWidth = tilesByX * tileCombined.getWidth(); const int pixmapHeight = tilesByY * tileCombined.getHeight(); - const size_t pixmapSize = 4 * pixmapWidth * pixmapHeight; - std::vector pixmap(pixmapSize, 0); +std::unique_lock lock(ChildSession::getLock()); +if (!_loKitDocument) +{ +Log::error("Tile rendering requested before loading document."); +return; +} + Timestamp timestamp; _loKitDocument->paintPartTile(pixmap.data(), tileCombined.getPart(), pixmapWidth, pixmapHeight, renderArea.getLeft(), renderArea.getTop(), renderArea.getWidth(), renderArea.getHeight()); - Log::debug() << "paintTile (combined) called, tile at [" << renderArea.getLeft() << ", " << renderArea.getTop() << "]" << " (" << renderArea.getWidth() << ", " << renderArea.getHeight() << ") rendered in " << double(timestamp.elapsed())/1000 << " ms." << Log::end; - +const auto mode = static_cast(_loKitDocument->getTileMode()); +lock.unlock(); std::vector output; output.reserve(pixmapWidth * pixmapHeight * 4); -const auto mode = static_cast(_loKitDocument->getTileMode()); size_t tileIndex = 0; for (Util::Rectangle& tileRect : tileRecs) { ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp |7 ++- 1 file changed, 2 insertions(+), 5 deletions(-) New commits: commit 1134b17e96b365cdd3638d7ef3942c90c37f7712 Author: Ashod Nakashian Date: Sun May 22 11:25:43 2016 -0400 loolwsd: logging Change-Id: Ic08b32104db1154573b9e0774cda23167a5cddf3 Reviewed-on: https://gerrit.libreoffice.org/25334 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 8cd6329..f2ba282 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -573,10 +573,6 @@ public: return; } -//TODO: Support multiviews. -//if (_multiView) -//_loKitDocument->setView(_viewId); - // Send back the request with all optional parameters given in the request. const auto tileMsg = tile.serialize("tile:"); #if ENABLE_DEBUG @@ -599,13 +595,14 @@ public: tile.getTilePosX(), tile.getTilePosY(), tile.getTileWidth(), tile.getTileHeight()); Log::trace() << "paintTile at (" << tile.getPart() << ',' << tile.getTilePosX() << ',' << tile.getTilePosY() - << " rendered in " << (timestamp.elapsed()/1000.) << " ms" << Log::end; + << ") rendered in " << (timestamp.elapsed()/1000.) << " ms" << Log::end; const auto mode = static_cast(_loKitDocument->getTileMode()); if (!png::encodeBufferToPNG(pixmap.data(), tile.getWidth(), tile.getHeight(), output, mode)) { //FIXME: Return error. //sendTextFrame("error: cmd=tile kind=failure"); +Log::error("Failed to encode tile into PNG."); return; } ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 64 1 file changed, 15 insertions(+), 49 deletions(-) New commits: commit 6e033a4c254da25a071ef36343a4ad192650e386 Author: Ashod Nakashian Date: Sat May 21 10:42:48 2016 -0400 loolwsd: use TileDesc in LOOLKit Change-Id: I8800cc5625db4b333933ec056649c3efbd486f68 Reviewed-on: https://gerrit.libreoffice.org/25265 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 9ac1d19..daf58b1 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -51,6 +51,7 @@ #include "LibreOfficeKit.hpp" #include "Log.hpp" #include "QueueHandler.hpp" +#include "TileDesc.hpp" #include "Unit.hpp" #include "UserMessages.hpp" #include "Util.hpp" @@ -561,45 +562,7 @@ public: void renderTile(StringTokenizer& tokens, const std::shared_ptr& ws) { -const auto tileMsg = Poco::cat(std::string(" "), tokens.begin() + 1, tokens.end()); -int part, width, height, tilePosX, tilePosY, tileWidth, tileHeight; - -if (tokens.count() < 8 || -!getTokenInteger(tokens[1], "part", part) || -!getTokenInteger(tokens[2], "width", width) || -!getTokenInteger(tokens[3], "height", height) || -!getTokenInteger(tokens[4], "tileposx", tilePosX) || -!getTokenInteger(tokens[5], "tileposy", tilePosY) || -!getTokenInteger(tokens[6], "tilewidth", tileWidth) || -!getTokenInteger(tokens[7], "tileheight", tileHeight)) -{ -//FIXME: Return error. -//sendTextFrame("error: cmd=tile kind=syntax"); -Log::error("Invalid tile request [" + tileMsg + "]."); -return; -} - -if (part < 0 || -width <= 0 || -height <= 0 || -tilePosX < 0 || -tilePosY < 0 || -tileWidth <= 0 || -tileHeight <= 0) -{ -//FIXME: Return error. -//sendTextFrame("error: cmd=tile kind=invalid"); -Log::error("Invalid tile request [" + tileMsg + "]."); -return; -} - -size_t index = 8; -int id = -1; -if (tokens.count() > index && tokens[index].find("id") == 0) -{ -getTokenInteger(tokens[index], "id", id); -++index; -} +auto tile = TileDesc::parse(tokens); std::unique_lock lock(ChildSession::getLock()); @@ -614,29 +577,31 @@ public: //_loKitDocument->setView(_viewId); // Send back the request with all optional parameters given in the request. +const auto tileMsg = tile.serialize("tile:"); #if ENABLE_DEBUG -const std::string response = "tile: " + tileMsg + " renderid=" + Util::UniqueId() + "\n"; +const std::string response = tileMsg + " renderid=" + Util::UniqueId() + "\n"; #else -const std::string response = "tile: " + tileMsg + "\n"; +const std::string response = tileMsg + "\n"; #endif std::vector output; -output.reserve(response.size() + (4 * width * height)); +output.reserve(response.size() + (4 * tile.getWidth() * tile.getHeight())); output.resize(response.size()); std::memcpy(output.data(), response.data(), response.size()); std::vector pixmap; -pixmap.resize(4 * width * height); +pixmap.resize(output.capacity()); Timestamp timestamp; -_loKitDocument->paintPartTile(pixmap.data(), part, - width, height, tilePosX, tilePosY, - tileWidth, tileHeight); -Log::trace() << "paintTile at [" << tilePosX << ", " << tilePosY - << "] rendered in " << (timestamp.elapsed()/1000.) << " ms" << Log::end; +_loKitDocument->paintPartTile(pixmap.data(), tile.getPart(), + tile.getWidth(), tile.getHeight(), + tile.getTilePosX(), tile.getTilePosY(), + tile.getTileWidth(), tile.getTileHeight()); +Log::trace() << "paintTile at (" << tile.getPart() << ',' << tile.getTilePosX() << ',' << tile.getTilePosY() + << " rendered in " << (timestamp.elapsed()/1000.) << " ms" << Log::end; const auto mode = static_cast(_loKitDocument->getTileMode()); -if (!Util::encodeBufferToPNG(pixmap.data(), width, height, output, mode)) +if (!Util::encodeBufferToPNG(pixmap.data(), tile.getWidth(), tile.getHeight(), output, mode)) { //FIXME: Return error. //sendTextFrame("error: cmd=tile kind=failure"); @@ -1257,6 +1222,7 @@ void lokit_main(const std::string& childRoot, Log::debug(socketName + ": recv [" + LOOLProtocol::getAbbreviatedMessage(message) + "]."); StringTo
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 18 +- 1 file changed, 9 insertions(+), 9 deletions(-) New commits: commit 312b9ee6cbb9502b3b2c01790fb7e24dcc5feb69 Author: Ashod Nakashian Date: Wed May 18 06:55:25 2016 -0400 loolwsd: less naked pointers Change-Id: I5f352a80a181f410c002d60b9ec5c61fb88d0cf0 Reviewed-on: https://gerrit.libreoffice.org/25095 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index c864691..528e690 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -864,7 +864,7 @@ private: try { load(sessionId, uri, docPassword, renderOpts, haveDocPassword); -if (!_loKitDocument) +if (!_loKitDocument || !_loKitDocument->get()) { return nullptr; } @@ -876,7 +876,7 @@ private: } // Done loading, let the next one in (if any). -assert(_loKitDocument && "Uninitialized lok::Document instance"); +assert(_loKitDocument && _loKitDocument->get() && "Uninitialized lok::Document instance"); lock.lock(); ++_clientViews; --_isLoading; @@ -918,11 +918,11 @@ private: private: -LibreOfficeKitDocument* load(const std::string& sessionId, - const std::string& uri, - const std::string& docPassword, - const std::string& renderOpts, - bool haveDocPassword) +std::shared_ptr load(const std::string& sessionId, +const std::string& uri, +const std::string& docPassword, +const std::string& renderOpts, +bool haveDocPassword) { const unsigned intSessionId = Util::decodeId(sessionId); const auto it = _connections.find(intSessionId); @@ -959,7 +959,7 @@ private: _loKitDocument = _loKit->documentLoad(uri.c_str()); Log::debug("Returned lokit::documentLoad."); -if (!_loKitDocument) +if (!_loKitDocument || !_loKitDocument->get()) { Log::error("Failed to load: " + uri + ", error: " + _loKit->getError()); @@ -1028,7 +1028,7 @@ private: } } -return _loKitDocument->get(); +return _loKitDocument; } private: ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp |2 +- 1 file changed, 1 insertion(+), 1 deletion(-) New commits: commit 797e41ca56bfd8cac3718dfb4943a25132b233b0 Author: Henry Castro Date: Wed May 11 19:46:51 2016 -0400 loolwsd: fix wrong condition diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index af05e17..309cc65 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -290,7 +290,7 @@ public: return true; }, [&session]() { session->closeFrame(); }, -[&queueHandlerThread]() { return TerminationFlag && queueHandlerThread.isRunning(); }); +[&queueHandlerThread]() { return TerminationFlag || !queueHandlerThread.isRunning(); }); queue->clear(); queue->put("eof"); ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 12 +--- 1 file changed, 9 insertions(+), 3 deletions(-) New commits: commit 27497ba4dcd363f060b6dcce7f2672e926566fa8 Author: Pranav Kant Date: Fri May 6 14:47:04 2016 +0530 loolwsd: Fix tile previews for viewing sessions Also, don't let these tile previews change part of the document permanently. This is a temporary solution till we have some better API from LOKit to deal with such a situation. Change-Id: I8dfefd2b7ad8cf3e7a57afb95b57994ef0bb3b6c diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 3d80548..60b3e02 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -659,10 +659,10 @@ public: std::vector pixmap; pixmap.resize(4 * width * height); - -if (part != _loKitDocument->pClass->getPart(_loKitDocument)) +int oldPart = _loKitDocument->pClass->getPart(_loKitDocument); +if (part != oldPart) { -if (editLock) +if (editLock || id != -1) { _loKitDocument->pClass->setPart(_loKitDocument, part); } @@ -689,6 +689,12 @@ public: return; } +// restore the original part if tilepreview request changed the part +if (id != -1) +{ +_loKitDocument->pClass->setPart(_loKitDocument, oldPart); +} + const auto length = output.size(); if (length > SMALL_MESSAGE_SIZE) { ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 22 +- 1 file changed, 17 insertions(+), 5 deletions(-) New commits: commit 1f990d3fc2e85dab478f26971ebe1927c9d2f381 Author: Pranav Kant Date: Fri May 6 14:44:03 2016 +0530 loolwsd: Fix incorrect position of id=, editlock= params editlock= is always the last parameter. This fixes the slide previews in impress documents for editing session. Change-Id: I3531c7f52e09e655524fa0afd6fe66da504b5d70 diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index cebb4c9..3d80548 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -578,6 +578,8 @@ public: { int part, width, height, tilePosX, tilePosY, tileWidth, tileHeight; +// There would be another param, editlock=, as the last parameter. +// For presentations, it would be followed by id= if (tokens.count() < 9 || !getTokenInteger(tokens[1], "part", part) || !getTokenInteger(tokens[2], "width", width) || @@ -589,6 +591,7 @@ public: { //FIXME: Return error. //sendTextFrame("error: cmd=tile kind=syntax"); +Log::error() << "Invalid tile request" << Log::end; return; } @@ -602,22 +605,31 @@ public: { //FIXME: Return error. //sendTextFrame("error: cmd=tile kind=invalid"); +Log::error() << "Invalid tile request" << Log::end; return; } -int editLock = 0; size_t index = 8; +int editLock = -1; +int id = -1; +if (tokens.count() > index && tokens[index].find("id") == 0) +{ +getTokenInteger(tokens[index], "id", id); +++index; +} + if (tokens.count() > index && tokens[index].find("editlock") == 0) { getTokenInteger(tokens[index], "editlock", editLock); ++index; } -int id = -1; -if (tokens.count() > index && tokens[index].find("id") == 0) +// For time being, editlock information in tile requests is mandatory +// till we have a better solution to handle multi-part documents +if (editLock == -1) { -getTokenInteger(tokens[index], "id", id); -++index; +Log::error("No editlock information found."); +return; } std::unique_lock lock(ChildProcessSession::getLock()); ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 12 +--- 1 file changed, 9 insertions(+), 3 deletions(-) New commits: commit 82333e06faea26bc019cdd8ea967bc8846650df6 Author: Ashod Nakashian Date: Wed May 4 06:55:56 2016 -0400 loolwsd: add explanation as to why code is commented out Change-Id: I3478d6c84cd960c4a7317ee5adc75db8c13aeaef Reviewed-on: https://gerrit.libreoffice.org/24647 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 2262e78..93b4a98 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -661,8 +661,14 @@ public: ws->sendFrame(output.data(), length, WebSocket::FRAME_BINARY); } -void sendCombinedTiles(const char* /*buffer*/, int /*length*/, StringTokenizer& tokens) +void sendCombinedTiles(const char* /*buffer*/, int /*length*/, StringTokenizer& /*tokens*/) { +// This is unnecessary at this point, since the DocumentBroker will send us individual +// tile requests (i.e. it breaks tilecombine requests). +// So unless DocumentBroker combines them again, there is no point in having this here. +// In fact, we probably want to remove this, since we always want to render individual +// tiles so that we can fetch them separately in the future. +#if 0 int part, pixelWidth, pixelHeight, tileWidth, tileHeight; std::string tilePositionsX, tilePositionsY; std::string reqTimestamp; @@ -690,7 +696,7 @@ public: if (tokens.count() > 8) getTokenString(tokens[8], "timestamp", reqTimestamp); -/* + bool makeSlow = delayAndRewritePart(part); Util::Rectangle renderArea; @@ -804,7 +810,7 @@ public: if (makeSlow) delay(); -*/ +#endif } private: ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp loolwsd/Unit.hpp
loolwsd/LOOLKit.cpp | 15 +++ loolwsd/Unit.hpp|6 ++ 2 files changed, 17 insertions(+), 4 deletions(-) New commits: commit 6b88e97b630f6d0c490f8af87054e8aab90f4d77 Author: Michael Meeks Date: Sun May 1 09:04:19 2016 +0100 Add unit test hook for libreofficekit. diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 14b2a85..a0b32cd 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -975,11 +975,18 @@ void lokit_main(const std::string& childRoot, instdir_path = "/" + loTemplate + "/program"; } -LibreOfficeKit* loKit = lok_init_2(instdir_path.c_str(), "file:///user"); -if (loKit == nullptr) +LibreOfficeKit* loKit; { -Log::error("LibreOfficeKit initialization failed. Exiting."); -std::_Exit(Application::EXIT_SOFTWARE); +const char *instdir = instdir_path.c_str(); +const char *userdir = "file:///user"; +loKit = UnitKit::get().lok_init(instdir, userdir); +if (!loKit) +loKit = lok_init_2(instdir, userdir); +if (loKit == nullptr) +{ +Log::error("LibreOfficeKit initialization failed. Exiting."); +std::_Exit(Application::EXIT_SOFTWARE); +} } Log::info("Process is ready."); diff --git a/loolwsd/Unit.hpp b/loolwsd/Unit.hpp index 6dc3045..dcdd36c 100644 --- a/loolwsd/Unit.hpp +++ b/loolwsd/Unit.hpp @@ -40,6 +40,7 @@ class StorageBase; typedef UnitBase *(CreateUnitHooksFunction)(); extern "C" { UnitBase *unit_create_wsd(void); } extern "C" { UnitBase *unit_create_kit(void); } +extern "C" { typedef struct _LibreOfficeKit LibreOfficeKit; } /// Derive your WSD unit test / hooks from me. class UnitBase @@ -186,6 +187,11 @@ public: virtual bool filterKitMessage(const std::shared_ptr & /* ws */, std::string &/* message */) { return false; } + +/// Allow a custom LibreOfficeKit wrapper +virtual LibreOfficeKit *lok_init(const char * /* instdir */, + const char * /* userdir */) +{ return NULL; } }; #endif ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 20 ++-- 1 file changed, 18 insertions(+), 2 deletions(-) New commits: commit 3aadd910c6e32c0e557671effa5a4c606cd6e8bf Author: Tor Lillqvist Date: Mon Apr 18 13:11:30 2016 +0300 We can't remove jailPath when inside the chroot as it does not exist there When inside the chroot, what we would need to do is remove everything below / . But doing that is a bit too risky, in case some developer screws up some detail and that code happens to run outside the chroot after all, and the developer's machine gets trashed. So just remove paths we can reasonably assume won't exist as global pathnames on a developer machine: loSubPath and JAILED_DOCUMENT_ROOT. Currently the actual complete cleanup of loolkit jails happens in loolwsd when it is exiting. That is a bug and will have to be fixed. It should be done in loolforkit as soon as possible after the loolkit process has exited. diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 4a2f94d..8a4b8e4 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -1054,10 +1054,26 @@ void lokit_main(const std::string& childRoot, return TerminationFlag; }); -// Cleanup a jail if we created one +// Clean up jail if we created one if (bRunInsideJail && !jailPath.isRelative()) { -Util::removeFile(jailPath, true); +// In theory we should here do Util::removeFile("/", true), because we are inside the +// chroot jail, and all of it can be removed now when we are exiting. (At least the root +// of the chroot jail probably would not be removed even if we tried, so we still would +// need to complete the cleanup in loolforkit.) + +// But: It is way too risky to actually do that (effectively, "rm -rf /") as it would +// trash a developer's machine if something goes wrong while hacking and debugging and +// the process isn't in a chroot after all when it comes here. + +// So just remove what we can reasonably safely assume won't exist as global pathnames +// on a developer's machine, loSubpath (typically "/lo") and JAILED_DOCUMENT_ROOT +// ("/user/docs/"). + +Log::info("Removing '/" + loSubPath + "'"); +Util::removeFile("/" + loSubPath, true); +Log::info("Removing '" + std::string(JAILED_DOCUMENT_ROOT) + "'"); +Util::removeFile(std::string(JAILED_DOCUMENT_ROOT), true); } } catch (const Exception& exc) ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp loolwsd/LOOLWSD.cpp loolwsd/loolwsd-systemplate-setup
loolwsd/LOOLKit.cpp | 42 -- loolwsd/LOOLWSD.cpp |1 loolwsd/loolwsd-systemplate-setup |8 --- 3 files changed, 32 insertions(+), 19 deletions(-) New commits: commit ebfa339da02337274d332763b0e1ace952550f2a Author: Michael Meeks Date: Fri Apr 15 16:16:36 2016 +0100 Cleanup symlinking and add realpath symlink if necessary. diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 18b0da2..7f55ec9 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -16,6 +16,9 @@ #include #include #include +#include +#include +#include #include #include @@ -820,6 +823,27 @@ private: std::atomic_size_t _clientViews; }; +namespace { +void symlinkPathToJail(const Path jailPath, const std::string &loTemplate, + const std::string &loSubPath) +{ +Path symlinkSource(jailPath, Path(loTemplate.substr(1))); +File(symlinkSource.parent()).createDirectories(); + +std::string symlinkTarget; +for (auto i = 0; i < Path(loTemplate).depth(); i++) +symlinkTarget += "../"; +symlinkTarget += loSubPath; + +Log::debug("symlink(\"" + symlinkTarget + "\",\"" + symlinkSource.toString() + "\")"); +if (symlink(symlinkTarget.c_str(), symlinkSource.toString().c_str()) == -1) +{ +Log::syserror("symlink(\"" + symlinkTarget + "\",\"" + symlinkSource.toString() + "\") failed"); +throw Exception("symlink() failed"); +} +} +} + void lokit_main(const std::string& childRoot, const std::string& sysTemplate, const std::string& loTemplate, @@ -861,19 +885,15 @@ void lokit_main(const std::string& childRoot, // Create a symlink inside the jailPath so that the absolute pathname loTemplate, when // interpreted inside a chroot at jailPath, points to loSubPath (relative to the chroot). -Path symlinkSource(jailPath, Path(loTemplate.substr(1))); -File(symlinkSource.parent()).createDirectories(); - -std::string symlinkTarget; -for (auto i = 0; i < Path(loTemplate).depth(); i++) -symlinkTarget += "../"; -symlinkTarget += loSubPath; +symlinkPathToJail(jailPath, loTemplate, loSubPath); -Log::debug("symlink(\"" + symlinkTarget + "\",\"" + symlinkSource.toString() + "\")"); -if (symlink(symlinkTarget.c_str(), symlinkSource.toString().c_str()) == -1) +// Font paths can end up as realpaths so match that too. +char *resolved = realpath(loTemplate.c_str(), NULL); +if (resolved) { -Log::syserror("symlink(\"" + symlinkTarget + "\",\"" + symlinkSource.toString() + "\") failed"); -throw Exception("symlink() failed"); +if (strcmp(loTemplate.c_str(), resolved)) +symlinkPathToJail(jailPath, std::string(resolved), loSubPath); +free (resolved); } Path jailLOInstallation(jailPath, loSubPath); diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index 31ed0d2..db27edc 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -479,6 +479,7 @@ private: response.setStatus(HTTPResponse::HTTP_NOT_FOUND); response.setContentLength(0); response.send(); +Log::info("file not found."); } } else diff --git a/loolwsd/loolwsd-systemplate-setup b/loolwsd/loolwsd-systemplate-setup index d6539e3..27c760c 100755 --- a/loolwsd/loolwsd-systemplate-setup +++ b/loolwsd/loolwsd-systemplate-setup @@ -87,14 +87,6 @@ if [ -h usr/share/fonts/ghostscript ]; then cp -r -p /usr/share/ghostscript/fonts usr/share/ghostscript fi -# Our Libreoffice install often comes with pre-bundled fonts. -# we need to ensure that there is a link to these with the same -# path that fontconfig found. -mkdir -p ./lo -mkdir -p ./$INSTDIR -rmdir ./$INSTDIR -ln -s /lo $CHROOT/$INSTDIR - # Debugging only hackery to avoid confusion. if test "z$ENABLE_DEBUG" != "z" -a "z$HOME" != "z"; then echo "Copying development users's fonts into systemplate" ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 11 ++- 1 file changed, 6 insertions(+), 5 deletions(-) New commits: commit 65ee0a1cdd95b544028f18a30ded9aad92806d7b Author: Ashod Nakashian Date: Wed Apr 13 07:18:30 2016 -0400 loolwsd: corrected etc file copying Change-Id: Ie920bbdee38d4b0a338753a6d483e274052939ce Reviewed-on: https://gerrit.libreoffice.org/24053 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index fe168e2..2b16af4 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -951,19 +951,20 @@ void lokit_main(const std::string& childRoot, bLoopMounted ? COPY_NO_USR : COPY_ALL); linkOrCopy(loTemplate, jailLOInstallation, COPY_LO); -Log::debug("Initialized jail files."); - // We need this because sometimes the hostname is not resolved -const std::vector networkFiles = {"/etc/host.conf", "/etc/hosts", "/etc/nsswitch.conf", "/etc/resolv.conf"}; +const auto networkFiles = {"/etc/host.conf", "/etc/hosts", "/etc/nsswitch.conf", "/etc/resolv.conf"}; for (const auto& filename : networkFiles) { +const auto etcPath = Path(jailPath, filename).toString(); const File networkFile(filename); -if (networkFile.exists()) +if (networkFile.exists() && !File(etcPath).exists()) { -networkFile.copyTo(Path(jailPath, "/etc").toString()); +networkFile.copyTo(etcPath); } } +Log::debug("Initialized jail files."); + // Create the urandom and random devices File(Path(jailPath, "/dev")).createDirectory(); if (mknod((jailPath.toString() + "/dev/random").c_str(), ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp |2 -- 1 file changed, 2 deletions(-) New commits: commit 2a65f2e397d2b830ba02df72759883f1dbda0448 Author: Ashod Nakashian Date: Sun Apr 10 13:07:20 2016 -0400 loolwsd: invoking disconnect on the session from Connection deadlocks Connection thread should not attempt to disconnect the session, which in turn will try to unload the document, which will wait on the connection to destroy. The latter will never happen since the connection destructor must, correctly, wait for its thread to finish, which is waiting on itself now. Since the session disconnect is already called from the session destructor, there is no need to explicitly invoke it here. Change-Id: Iaf9e8a10d4caa9001208084e909a14b4d4c5105e Reviewed-on: https://gerrit.libreoffice.org/23966 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 52083d4..ef16180 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -340,8 +340,6 @@ public: queue->clear(); queue->put("eof"); queueHandlerThread.join(); - -_session->disconnect(); } catch (const Exception& exc) { ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 117 ++-- 1 file changed, 68 insertions(+), 49 deletions(-) New commits: commit 653da3a409faae5d4d6cc8b59f0c9900b70a3764 Author: Ashod Nakashian Date: Sat Apr 2 20:43:02 2016 -0400 loolwsd: Document::onLoad is now exception safe In face of exceptions, the lock was not released and the condition variable was not signalled, thereby causing all subsequent views on the same document to fail loading. Change-Id: I18d3cefcc74a158facefe1e74a9c802ee048b014 Reviewed-on: https://gerrit.libreoffice.org/23785 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index b37269b..9c56fb7 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -629,7 +629,6 @@ private: LibreOfficeKitDocument* onLoad(const std::string& sessionId, const std::string& uri, const std::string& docPassword, bool isDocPasswordProvided) { Log::info("Session " + sessionId + " is loading. " + std::to_string(_clientViews) + " views loaded."); -const unsigned intSessionId = Util::decodeId(sessionId); std::unique_lock lock(_mutex); while (_isLoading) @@ -641,10 +640,70 @@ private: ++_isLoading; lock.unlock(); +try +{ +load(sessionId, uri, docPassword, isDocPasswordProvided); +} +catch (const std::exception& exc) +{ +Log::error("Exception while loading [" + uri + "] : " + exc.what()); +} + +// Done loading, let the next one in (if any). +lock.lock(); +++_clientViews; +--_isLoading; +_cvLoading.notify_one(); + +return _loKitDocument; +} + +void onUnload(const std::string& sessionId) +{ +const unsigned intSessionId = Util::decodeId(sessionId); +const auto it = _connections.find(intSessionId); +if (it == _connections.end() || !it->second || !_loKitDocument) +{ +// Nothing to do. +return; +} + +auto session = it->second->getSession(); +auto sessionLock = session->getLock(); +std::unique_lock lock(_mutex); + +--_clientViews; + +std::ostringstream message; +message << "rmview" << " " +<< Process::id() << " " +<< sessionId << " " +<< "\n"; +IoUtil::writeFIFO(WriterNotify, message.str()); + +Log::info("Session " + sessionId + " is unloading. " + std::to_string(_clientViews) + " views will remain."); + +if (_multiView && _loKitDocument) +{ +Log::info() << "Document [" << _url << "] session [" +<< sessionId << "] unloaded, leaving " +<< _clientViews << " views." << Log::end; + +const auto viewId = _loKitDocument->pClass->getView(_loKitDocument); +_loKitDocument->pClass->registerCallback(_loKitDocument, nullptr, nullptr); +_loKitDocument->pClass->destroyView(_loKitDocument, viewId); +} +} + +private: + +LibreOfficeKitDocument* load(const std::string& sessionId, const std::string& uri, const std::string& docPassword, bool isDocPasswordProvided) +{ +const unsigned intSessionId = Util::decodeId(sessionId); const auto it = _connections.find(intSessionId); if (it == _connections.end() || !it->second) { -Log::error("Cannot find session [" + sessionId + "] which decoded to " + std::to_string(intSessionId)); +Log::error("Cannot find session [" + sessionId + "]."); return nullptr; } @@ -667,8 +726,12 @@ private: _docPassword = docPassword; _jailedUrl = uri; _isDocPasswordProtected = false; -Log::info("Calling _loKit->pClass->documentLoad"); -if ((_loKitDocument = _loKit->pClass->documentLoad(_loKit, uri.c_str())) == nullptr) + +Log::debug("Calling documentLoad"); +_loKitDocument = _loKit->pClass->documentLoad(_loKit, uri.c_str()); +Log::debug("documentLoad returned"); + +if (_loKitDocument == nullptr) { Log::error("Failed to load: " + uri + ", error: " + _loKit->pClass->getError(_loKit)); @@ -690,7 +753,6 @@ private: return nullptr; } -Log::info("documentLoad() returned"); // Notify the Admin thread std::ostringstream message; @@ -739,59 +801,16 @@ private: } } -// Done loading, let the next one in (if any). -lock.lock(); -++_clientViews; ---_isLoading; -_cvLoading.notify_one(); - std::ostringstream message; message << "addview" << " " << Process::id() << " " << sessionId <<
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp loolwsd/loolmount.c loolwsd/Makefile.am
loolwsd/LOOLKit.cpp | 61 +++- loolwsd/Makefile.am |5 +++- loolwsd/loolmount.c | 30 + 3 files changed, 85 insertions(+), 11 deletions(-) New commits: commit 1b25179b25992f78600b7b102d6cdc890ce6c1a3 Author: Michael Meeks Date: Sat Apr 2 19:17:22 2016 +0100 Use bind mounting to accelerate jail creation. of the 10k files still linked into the jail; 5700 are from usr/ so bind mount just that directory, also set noatime, ro, and some other helpful looking options. Change-Id: I28d2d5cbbdf33fb57ea0f0c0915cb267603ee16d Reviewed-on: https://gerrit.libreoffice.org/23777 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 23c498f..d6a0334 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -76,9 +76,33 @@ static int writerNotify = -1; namespace { +typedef enum { COPY_ALL, COPY_LO, COPY_NO_USR } LinkOrCopyType; +LinkOrCopyType linkOrCopyType; std::string sourceForLinkOrCopy; Path destinationForLinkOrCopy; +bool shouldCopyDir(const char *path) +{ +switch (linkOrCopyType) +{ +case COPY_NO_USR: +// bind mounted. +return strcmp(path,"usr"); +case COPY_LO: +return +strcmp(path, "program/wizards") && +strcmp(path, "sdk") && +strcmp(path, "share/basic") && +strcmp(path, "share/gallery") && +strcmp(path, "share/Scripts") && +strcmp(path, "share/template") && +strcmp(path, "share/config/wizard") && +strcmp(path, "share/config/wizard"); +default: // COPY_ALL +return true; +} +} + int linkOrCopyFunction(const char *fpath, const struct stat* /*sb*/, int typeflag, @@ -110,13 +134,7 @@ namespace Log::error("Error: stat(\"" + std::string(fpath) + "\") failed."); return 1; } -if (!strcmp(relativeOldPath, "program/wizards") || -!strcmp(relativeOldPath, "sdk") || -!strcmp(relativeOldPath, "share/gallery") || -!strcmp(relativeOldPath, "share/Scripts") || -!strcmp(relativeOldPath, "share/template") || -!strcmp(relativeOldPath, "share/config/wizard") || -!strcmp(relativeOldPath, "share/config/wizard")) +if (!shouldCopyDir(relativeOldPath)) { Log::debug("skip redundant paths " + std::string(relativeOldPath)); return FTW_SKIP_SUBTREE; @@ -149,8 +167,11 @@ namespace return 0; } -void linkOrCopy(const std::string& source, const Path& destination) +void linkOrCopy(const std::string& source, +const Path& destination, +LinkOrCopyType type) { +linkOrCopyType = type; sourceForLinkOrCopy = source; if (sourceForLinkOrCopy.back() == '/') sourceForLinkOrCopy.pop_back(); @@ -902,8 +923,26 @@ void lokit_main(const std::string& childRoot, File(jailLOInstallation).createDirectory(); // Copy (link) LO installation and other necessary files into it from the template. -linkOrCopy(sysTemplate, jailPath); -linkOrCopy(loTemplate, jailLOInstallation); +bool bLoopMounted = false; +if (getenv("LOOL_BIND_MOUNT")) +{ +Path usrSrcPath(sysTemplate, "usr"); +Path usrDestPath(jailPath, "usr"); +File(usrDestPath).createDirectory(); +std::string mountCommand = +std::string("loolmount ") + +usrSrcPath.toString() + +std::string(" ") + +usrDestPath.toString(); +Log::debug("Initializing jail bind mount."); +bLoopMounted = !system(mountCommand.c_str()); +Log::debug("Initialized jail bind mount."); +} +linkOrCopy(sysTemplate, jailPath, + bLoopMounted ? COPY_NO_USR : COPY_ALL); +linkOrCopy(loTemplate, jailLOInstallation, COPY_LO); + +Log::debug("Initialized jail files."); // We need this because sometimes the hostname is not resolved const std::vector networkFiles = {"/etc/host.conf", "/etc/hosts", "/etc/nsswitch.conf", "/etc/resolv.conf"}; @@ -949,6 +988,8 @@ void lokit_main(const std::string& childRoot, dropCapability(CAP_MKNOD); dropCapability(CAP_FOWNER); +Log::debug("Initialized jail nodes, dropped caps."); + loKit = lok_init_2(instdir_path.c_str(), "file:///user"); if (loKit == nullptr) { diff --git a/loolwsd/Makefile.am b/loolwsd/Makefile.am index f3f5
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp |2 +- 1 file changed, 1 insertion(+), 1 deletion(-) New commits: commit 4d2cd2fff3d22de1c28b3dc0babef61bdf86af95 Author: Michael Meeks Date: Fri Apr 1 23:19:15 2016 +0100 More helpful exception debug. Change-Id: Ibc76f20ba0ff9e015632bff2b7f049d40d49064b Reviewed-on: https://gerrit.libreoffice.org/23772 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 848dbf8..620a40b 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -447,7 +447,7 @@ public: } catch (const std::exception& ex) { -Log::error("Exception while creating session [" + sessionId + "] on url [" + _url + "]."); +Log::error("Exception while creating session [" + sessionId + "] on url [" + _url + "] - '" + ex.what() + "'."); return false; } } ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp loolwsd/LOOLWSD.cpp
loolwsd/LOOLKit.cpp | 22 ++ loolwsd/LOOLWSD.cpp |2 -- 2 files changed, 10 insertions(+), 14 deletions(-) New commits: commit 9266ffc09fdea870cc66d6cb71b4a12dff361c43 Author: Michael Meeks Date: Fri Apr 1 23:07:32 2016 +0100 Remove apparently un-necessary thread local variable template. Change-Id: Ia220aff972827a0e49a8dadcdb8f32dcd3eed8c9 Reviewed-on: https://gerrit.libreoffice.org/23771 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 2794609..848dbf8 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -38,7 +38,6 @@ #include #include #include -#include #include #include @@ -68,7 +67,6 @@ using Poco::Process; using Poco::Runnable; using Poco::StringTokenizer; using Poco::Thread; -using Poco::ThreadLocal; using Poco::Util::Application; const std::string FIFO_BROKER = "loolbroker.fifo"; @@ -78,20 +76,20 @@ static int writerNotify = -1; namespace { -ThreadLocal sourceForLinkOrCopy; -ThreadLocal destinationForLinkOrCopy; +std::string sourceForLinkOrCopy; +Path destinationForLinkOrCopy; int linkOrCopyFunction(const char *fpath, const struct stat* /*sb*/, int typeflag, struct FTW* /*ftwbuf*/) { -if (strcmp(fpath, sourceForLinkOrCopy->c_str()) == 0) +if (strcmp(fpath, sourceForLinkOrCopy.c_str()) == 0) return 0; -assert(fpath[strlen(sourceForLinkOrCopy->c_str())] == '/'); -const char *relativeOldPath = fpath + strlen(sourceForLinkOrCopy->c_str()) + 1; -Path newPath(*destinationForLinkOrCopy, Path(relativeOldPath)); +assert(fpath[strlen(sourceForLinkOrCopy.c_str())] == '/'); +const char *relativeOldPath = fpath + strlen(sourceForLinkOrCopy.c_str()) + 1; +Path newPath(destinationForLinkOrCopy, Path(relativeOldPath)); switch (typeflag) { @@ -153,10 +151,10 @@ namespace void linkOrCopy(const std::string& source, const Path& destination) { -*sourceForLinkOrCopy = source; -if (sourceForLinkOrCopy->back() == '/') -sourceForLinkOrCopy->pop_back(); -*destinationForLinkOrCopy = destination; +sourceForLinkOrCopy = source; +if (sourceForLinkOrCopy.back() == '/') +sourceForLinkOrCopy.pop_back(); +destinationForLinkOrCopy = destination; if (nftw(source.c_str(), linkOrCopyFunction, 10, FTW_ACTIONRETVAL) == -1) Log::error("linkOrCopy: nftw() failed for '" + source + "'"); } diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index 1dd6eef..033c2ec 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -101,7 +101,6 @@ DEALINGS IN THE SOFTWARE. #include #include #include -#include #include #include #include @@ -157,7 +156,6 @@ using Poco::StreamCopier; using Poco::StringTokenizer; using Poco::TemporaryFile; using Poco::Thread; -using Poco::ThreadLocal; using Poco::ThreadPool; using Poco::URI; using Poco::Util::Application; ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 17 +++-- 1 file changed, 15 insertions(+), 2 deletions(-) New commits: commit 23672ac3626ff2d0691506ac60a81883ca37f738 Author: Michael Meeks Date: Fri Apr 1 23:01:31 2016 +0100 Build jails more sparingly eliding un-necessary directories. Create directories top-down and not bottom up for more efficiency too. Skip the sdk (if we have it) - ~20k files, and misc. other pieces that we don't need; still more to go there. Change-Id: Iccd9ebac495fba414d268b339ef82a161d98a9ca Reviewed-on: https://gerrit.libreoffice.org/23770 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index f8699b3..2794609 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -104,7 +104,7 @@ namespace std::exit(Application::EXIT_SOFTWARE); } break; -case FTW_DP: +case FTW_D: { struct stat st; if (stat(fpath, &st) == -1) @@ -112,6 +112,17 @@ namespace Log::error("Error: stat(\"" + std::string(fpath) + "\") failed."); return 1; } +if (!strcmp(relativeOldPath, "program/wizards") || +!strcmp(relativeOldPath, "sdk") || +!strcmp(relativeOldPath, "share/gallery") || +!strcmp(relativeOldPath, "share/Scripts") || +!strcmp(relativeOldPath, "share/template") || +!strcmp(relativeOldPath, "share/config/wizard") || +!strcmp(relativeOldPath, "share/config/wizard")) +{ +Log::debug("skip redundant paths " + std::string(relativeOldPath)); +return FTW_SKIP_SUBTREE; +} File(newPath).createDirectories(); struct utimbuf ut; ut.actime = st.st_atime; @@ -133,7 +144,9 @@ namespace Log::error("nftw: symlink to nonexistent file: '" + std::string(fpath) + "', ignored."); break; default: +Log::error("nftw: unexpected type: '" + std::to_string(typeflag)); assert(false); +break; } return 0; } @@ -144,7 +157,7 @@ namespace if (sourceForLinkOrCopy->back() == '/') sourceForLinkOrCopy->pop_back(); *destinationForLinkOrCopy = destination; -if (nftw(source.c_str(), linkOrCopyFunction, 10, FTW_DEPTH) == -1) +if (nftw(source.c_str(), linkOrCopyFunction, 10, FTW_ACTIONRETVAL) == -1) Log::error("linkOrCopy: nftw() failed for '" + source + "'"); } } ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp |2 +- 1 file changed, 1 insertion(+), 1 deletion(-) New commits: commit d186e05a0d893b5afcc8c6246639c82502898be6 Author: Pranav Kant Date: Thu Mar 31 22:47:05 2016 +0530 loolwsd: Use filename in admin console ... instead of long URIs. Change-Id: I9d13285ce81967a4ff9eb518086743540d7a2a90 diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 2bce3e8..b10a08f 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -667,7 +667,7 @@ private: std::ostringstream message; message << "document" << " " << Process::id() << " " -<< _url << " " +<< uri.substr(uri.find_last_of("/") + 1) << " " << "\r\n"; IoUtil::writeFIFO(writerNotify, message.str()); ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 120 +++- 1 file changed, 72 insertions(+), 48 deletions(-) New commits: commit 4b38df745590119c5b10bbdefa67fcf7f5b33bf2 Author: Ashod Nakashian Date: Sun Mar 27 20:05:23 2016 -0400 loolwsd: lokit command handling improvements Change-Id: I81baddb30805ee1bce5399171a40e73a18af68bf Reviewed-on: https://gerrit.libreoffice.org/23640 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index eb8a683..fa98b6c 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -381,53 +381,64 @@ public: const std::string& getUrl() const { return _url; } -void createSession(const std::string& sessionId, const unsigned intSessionId) +bool createSession(const std::string& sessionId, const unsigned intSessionId) { std::unique_lock lock(_mutex); -const auto& it = _connections.find(intSessionId); -if (it != _connections.end()) +try { -// found item, check if still running -if (it->second->isRunning()) +const auto& it = _connections.find(intSessionId); +if (it != _connections.end()) { -Log::warn("Thread [" + sessionId + "] is already running."); -return; -} - -// Restore thread. -Log::warn("Thread [" + sessionId + "] is not running. Restoring."); -_connections.erase(intSessionId); -} - -Log::info() << "Creating " << (_clientViews ? "new" : "first") -<< " view for url: " << _url << " for sessionId: " << sessionId -<< " on jailId: " << _jailId << Log::end; +// found item, check if still running +if (it->second->isRunning()) +{ +Log::warn("Session [" + sessionId + "] is already running."); +return true; +} -// Open websocket connection between the child process and the -// parent. The parent forwards us requests that it can't handle (i.e most). +// Restore thread. TODO: Review this logic. +Log::warn("Session [" + sessionId + "] is not running. Restoring."); +_connections.erase(intSessionId); +} -HTTPClientSession cs("127.0.0.1", MASTER_PORT_NUMBER); -cs.setTimeout(0); -HTTPRequest request(HTTPRequest::HTTP_GET, std::string(CHILD_URI) + "sessionId=" + sessionId + "&jailId=" + _jailId + "&docKey=" + _docKey); -HTTPResponse response; +Log::info() << "Creating " << (_clientViews ? "new" : "first") +<< " view for url: " << _url << " for sessionId: " << sessionId +<< " on jailId: " << _jailId << Log::end; -auto ws = std::make_shared(cs, request, response); -ws->setReceiveTimeout(0); +// Open websocket connection between the child process and the +// parent. The parent forwards us requests that it can't handle (i.e most). +HTTPClientSession cs("127.0.0.1", MASTER_PORT_NUMBER); +cs.setTimeout(0); +HTTPRequest request(HTTPRequest::HTTP_GET, std::string(CHILD_URI) + "sessionId=" + sessionId + "&jailId=" + _jailId + "&docKey=" + _docKey); +HTTPResponse response; -auto session = std::make_shared(sessionId, ws, _loKitDocument, _jailId, - [this](const std::string& id, const std::string& uri, const std::string& docPassword, bool isDocPasswordProvided) { return onLoad(id, uri, docPassword, isDocPasswordProvided); }, - [this](const std::string& id) { onUnload(id); }); +auto ws = std::make_shared(cs, request, response); +ws->setReceiveTimeout(0); -auto thread = std::make_shared(session, ws); -const auto aInserted = _connections.emplace(intSessionId, thread); +auto session = std::make_shared(sessionId, ws, _loKitDocument, _jailId, + [this](const std::string& id, const std::string& uri, const std::string& docPassword, bool isDocPasswordProvided) { return onLoad(id, uri, docPassword, isDocPasswordProvided); }, + [this](const std::string& id) { onUnload(id); }); -if ( aInserted.second ) -thread->start(); -else -Log::error("Connection already exists for child: " + _jailId + ", thread: " + sessionId); +auto thread = std::make_shared(session, ws); +const auto aInserted = _connections.emplace(intSessionId, thread); +if (aInserted.second) +{ +thread->start(); +} +else +{ +Log::error("Connection already exists for child: " + _jailId + ", session: " +
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 69 +--- 1 file changed, 23 insertions(+), 46 deletions(-) New commits: commit 4305d333b23102c0f9d88bb083cad5c25825e162 Author: Ashod Nakashian Date: Sun Mar 27 19:44:21 2016 -0400 loolwsd: lokit process can only host one url in its lifetime Change-Id: I561e5b81a748b7ec567af9aff968ba5c66ad44bf Reviewed-on: https://gerrit.libreoffice.org/23639 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 9d9dbc5..eb8a683 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -793,21 +793,14 @@ void lokit_main(const std::string& childRoot, Util::rng::reseed(); #endif -struct pollfd pollPipeBroker; -ssize_t bytes = -1; -int ready = 0; -bool isUsedKit = false; -char buffer[READ_BUFFER_SIZE]; -char* start = nullptr; -char* end = nullptr; - assert(!childRoot.empty()); assert(!sysTemplate.empty()); assert(!loTemplate.empty()); assert(!loSubPath.empty()); assert(!pipe.empty()); -std::map> _documents; +// We only host a single document in our lifetime. +std::shared_ptr document; // Ideally this will be a random ID, but broker will cleanup // our jail directory when we die, and it's simpler to know @@ -939,27 +932,23 @@ void lokit_main(const std::string& childRoot, Log::info("loolkit [" + std::to_string(Process::id()) + "] is ready."); -std::string response; -std::string message; +char* start = nullptr; +char* end = nullptr; while (!TerminationFlag) { if (start == end) { +struct pollfd pollPipeBroker; pollPipeBroker.fd = readerBroker; pollPipeBroker.events = POLLIN; pollPipeBroker.revents = 0; -ready = poll(&pollPipeBroker, 1, POLL_TIMEOUT_MS); +const int ready = poll(&pollPipeBroker, 1, POLL_TIMEOUT_MS); if (ready == 0) { // time out maintenance -for (auto it = _documents.cbegin(); it != _documents.cend(); ) -{ -it = (it->second->canDiscard() ? _documents.erase(it) : ++it); -} - -if (isUsedKit && _documents.empty()) +if (document && document->canDiscard()) { Log::info("Document closed. Flagging for termination."); TerminationFlag = true; @@ -974,7 +963,8 @@ void lokit_main(const std::string& childRoot, else if (pollPipeBroker.revents & (POLLIN | POLLPRI)) { -bytes = IoUtil::readFIFO(readerBroker, buffer, sizeof(buffer)); +char buffer[READ_BUFFER_SIZE]; +const auto bytes = IoUtil::readFIFO(readerBroker, buffer, sizeof(buffer)); if (bytes < 0) { start = end = nullptr; @@ -994,6 +984,7 @@ void lokit_main(const std::string& childRoot, if (start != end) { +std::string message; char byteChar = *start++; while (start != end && byteChar != '\r' && byteChar != '\n') { @@ -1004,17 +995,11 @@ void lokit_main(const std::string& childRoot, if (byteChar == '\r' && *start == '\n') { start++; -StringTokenizer tokens(message, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM); -response = std::to_string(Process::id()) + " "; - Log::trace("Recv: " + message); +StringTokenizer tokens(message, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM); +auto response = std::to_string(Process::id()) + " "; -for (auto it = _documents.cbegin(); it != _documents.cend(); ) -{ -it = (it->second->canDiscard() ? _documents.erase(it) : ++it); -} - -if (TerminationFlag || (isUsedKit && _documents.empty())) +if (TerminationFlag || (document && document->canDiscard())) { TerminationFlag = true; response += "down \r\n"; @@ -1023,15 +1008,8 @@ void lokit_main(const std::string& childRoot, { if (tokens[1] == "url") { -if (_documents.empty()) -{ -response += "empty \r\n"; -} -else -
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp loolwsd/test
loolwsd/LOOLKit.cpp | 36 ++-- loolwsd/test/data/timeline.xlsx |binary 2 files changed, 26 insertions(+), 10 deletions(-) New commits: commit 82bd7a606a1e14f354a237e613ee0a3c6f5a17f1 Author: Ashod Nakashian Date: Fri Mar 25 12:31:48 2016 -0400 loolwsd: recursive_mutex -> mutex and new loading synchronization mechanics Change-Id: I20249ca56ca3e9203e6a989e6fe9972b6b4eca36 Reviewed-on: https://gerrit.libreoffice.org/23528 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 6158642..e4fa310 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -324,6 +325,7 @@ public: _isDocLoaded(false), _isDocPasswordProtected(false), _docPasswordType(PasswordType::ToView), +_isLoading(0), _clientViews(0) { (void)_isDocLoaded; // FIXME LOOLBroker.cpp includes LOOLKit.cpp @@ -366,7 +368,7 @@ public: } } -std::unique_lock lock(_mutex); +std::unique_lock lock(_mutex); // Destroy all connections and views. _connections.clear(); @@ -381,7 +383,7 @@ public: void createSession(const std::string& sessionId, const unsigned intSessionId) { -std::unique_lock lock(_mutex); +std::unique_lock lock(_mutex); const auto& it = _connections.find(intSessionId); if (it != _connections.end()) @@ -436,7 +438,7 @@ public: std::vector> deadSessions; size_t num_connections = 0; { -std::unique_lock lock(_mutex, std::defer_lock); +std::unique_lock lock(_mutex, std::defer_lock); if (!lock.try_lock()) { // Not a good time, try later. @@ -523,7 +525,7 @@ private: if (self) { -std::unique_lock lock(self->_mutex); +std::unique_lock lock(self->_mutex); for (auto& it: self->_connections) { if (it.second->isRunning()) @@ -567,7 +569,7 @@ private: Document* self = reinterpret_cast(pData); if (self) { -std::unique_lock lock(self->_mutex); +std::unique_lock lock(self->_mutex); for (auto& it: self->_connections) { @@ -589,7 +591,15 @@ private: Log::info("Session " + sessionId + " is loading. " + std::to_string(_clientViews) + " views loaded."); const unsigned intSessionId = Util::decodeId(sessionId); -std::unique_lock lock(_mutex); +std::unique_lock lock(_mutex); +while (_isLoading) +{ +_cvLoading.wait(lock); +} + +// Flag and release lock. +++_isLoading; +lock.unlock(); const auto it = _connections.find(intSessionId); if (it == _connections.end() || !it->second) @@ -605,7 +615,7 @@ private: // This is the first time we are loading the document Log::info("Loading new document from URI: [" + uri + "] for session [" + sessionId + "]."); -if ( LIBREOFFICEKIT_HAS(_loKit, registerCallback)) +if (LIBREOFFICEKIT_HAS(_loKit, registerCallback)) { _loKit->pClass->registerCallback(_loKit, KitCallback, this); _loKit->pClass->setOptionalFeatures(_loKit, LOK_FEATURE_DOCUMENT_PASSWORD | @@ -689,7 +699,11 @@ private: } } +// Done loading, let the next one in (if any). +lock.lock(); ++_clientViews; +--_isLoading; +_cvLoading.notify_one(); std::ostringstream message; message << "addview" << " " @@ -713,7 +727,7 @@ private: auto session = it->second->getSession(); auto sessionLock = session->getLock(); -std::unique_lock lock(_mutex); +std::unique_lock lock(_mutex); --_clientViews; @@ -760,9 +774,11 @@ private: // Whether password is required to view the document, or modify it PasswordType _docPasswordType; -std::recursive_mutex _mutex; +std::mutex _mutex; +std::condition_variable _cvLoading; +std::atomic_size_t _isLoading; std::map> _connections; -std::atomic _clientViews; +std::atomic_size_t _clientViews; }; void lokit_main(const std::string& childRoot, diff --git a/loolwsd/test/data/timeline.xlsx b/loolwsd/test/data/timeline.xlsx new file mode 100644 index 000..77a15f6 Binary files /dev/null and b/loolwsd/test/data/timeline.xlsx differ ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 19 ++- 1 file changed, 14 insertions(+), 5 deletions(-) New commits: commit 18829fda3b0b45118b99c193a72cd48469b4eb3f Author: Ashod Nakashian Date: Sat Mar 19 17:52:05 2016 -0400 loolwsd: opportunistic kit session cleanup When the Document lock cannot be taken purging doesn't block (which would block the kit-broker pipe). Instead, purging is done only when the lock is taken, otherwise we try again later. Change-Id: Id201f1c67803d9b1e765e8c55f85206795fe53c0 Reviewed-on: https://gerrit.libreoffice.org/23448 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index dcf5e61..6158642 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -403,7 +403,7 @@ public: << " on jailId: " << _jailId << Log::end; // Open websocket connection between the child process and the -// parent. The parent forwards us requests that it can't handle. +// parent. The parent forwards us requests that it can't handle (i.e most). HTTPClientSession cs("127.0.0.1", MASTER_PORT_NUMBER); cs.setTimeout(0); @@ -430,11 +430,18 @@ public: /// Purges dead connections and returns /// the remaining number of clients. +/// Returns -1 on failure. size_t purgeSessions() { std::vector> deadSessions; +size_t num_connections = 0; { -std::unique_lock lock(_mutex); +std::unique_lock lock(_mutex, std::defer_lock); +if (!lock.try_lock()) +{ +// Not a good time, try later. +return -1; +} for (auto it =_connections.cbegin(); it != _connections.cend(); ) { @@ -448,6 +455,8 @@ public: ++it; } } + +num_connections = _connections.size(); } // Don't destroy sessions while holding our lock. @@ -456,15 +465,15 @@ public: // and the dtor tries to take its lock (which is taken). deadSessions.clear(); -std::unique_lock lock(_mutex); -return _connections.size(); +return num_connections; } /// Returns true if at least one *live* connection exists. /// Does not consider user activity, just socket status. bool hasConnections() { -return purgeSessions() > 0; +// -ve values for failure. +return purgeSessions() != 0; } /// Returns true if there is no activity and ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp |5 - 1 file changed, 4 insertions(+), 1 deletion(-) New commits: commit f2eec85b2a84d58eb2d125f1a826d71fdcd85d4b Author: Ashod Nakashian Date: Sun Mar 13 11:02:47 2016 -0400 loolwsd: jailId ought be random, but must be PID Ideally, we will have a randomized path for the jails. Unfortunately, this will make it harder to cleanup after an ungraceful exit of a child, including recovery of docs etc. Having a PID for the jailId makes this issue easier by implicitly implying the jail path for a given child. To prevent security leaks, we should at least randomize the doc directory within the jail, as such: /chroot//user/docs// For now we use jailId=pid=rand. Change-Id: I948fba0aaef725c9c059780df0a184a86569d898 Reviewed-on: https://gerrit.libreoffice.org/23223 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 36ae9b4..dcf5e61 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -784,7 +784,10 @@ void lokit_main(const std::string& childRoot, std::map> _documents; -static const std::string jailId = Util::encodeId(Util::rng::getNext()); +// Ideally this will be a random ID, but broker will cleanup +// our jail directory when we die, and it's simpler to know +// the jailId (i.e. the path) implicitly by knowing our pid. +static const std::string jailId = std::to_string(Process::id()); static const std::string process_name = "loolkit"; if (prctl(PR_SET_NAME, reinterpret_cast(process_name.c_str()), 0, 0, 0) != 0) ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp loolwsd/MasterProcessSession.cpp loolwsd/MasterProcessSession.hpp
loolwsd/LOOLKit.cpp |7 ++- loolwsd/MasterProcessSession.cpp | 35 +++ loolwsd/MasterProcessSession.hpp |4 3 files changed, 5 insertions(+), 41 deletions(-) New commits: commit 29e9ba68c3fcf58c65a9272b8bb80369750fd0c4 Author: Ashod Nakashian Date: Sun Mar 13 11:02:12 2016 -0400 loolwsd: removed unnecessary childId, which is in the child URL Change-Id: Ibea2cd73657446ad4660400a0a9a38b376499df5 Reviewed-on: https://gerrit.libreoffice.org/23222 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 33aebe1..36ae9b4 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -399,8 +399,8 @@ public: } Log::info() << "Creating " << (_clientViews ? "new" : "first") -<< " view for url: " << _url << " for thread: " << sessionId -<< " on child: " << _jailId << Log::end; +<< " view for url: " << _url << " for sessionId: " << sessionId +<< " on jailId: " << _jailId << Log::end; // Open websocket connection between the child process and the // parent. The parent forwards us requests that it can't handle. @@ -416,9 +416,6 @@ public: auto session = std::make_shared(sessionId, ws, _loKitDocument, _jailId, [this](const std::string& id, const std::string& uri, const std::string& docPassword, bool isDocPasswordProvided) { return onLoad(id, uri, docPassword, isDocPasswordProvided); }, [this](const std::string& id) { onUnload(id); }); -// child -> 0, sessionId -> 1, PID -> 2 -const std::string hello("child " + sessionId + " " + _jailId); -session->sendTextFrame(hello); auto thread = std::make_shared(session, ws); const auto aInserted = _connections.emplace(intSessionId, thread); diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp index d78a762..e1b7a6d 100644 --- a/loolwsd/MasterProcessSession.cpp +++ b/loolwsd/MasterProcessSession.cpp @@ -112,7 +112,7 @@ bool MasterProcessSession::_handleInput(const char *buffer, int length) return true; } -if (haveSeparateProcess()) +if (_kind == Kind::ToPrisoner) { // Note that this handles both forwarding requests from the client to the child process, and // forwarding replies from the child process to the client. Or does it? @@ -120,7 +120,6 @@ bool MasterProcessSession::_handleInput(const char *buffer, int length) // Snoop at some messages and manipulate tile cache information as needed auto peer = _peer.lock(); -if (_kind == Kind::ToPrisoner) { if (!peer) { @@ -205,7 +204,7 @@ bool MasterProcessSession::_handleInput(const char *buffer, int length) } } -if (_kind == Kind::ToPrisoner && peer && peer->_tileCache && !_isDocPasswordProtected) +if (peer && peer->_tileCache && !_isDocPasswordProtected) { if (tokens[0] == "tile:") { @@ -280,31 +279,7 @@ bool MasterProcessSession::_handleInput(const char *buffer, int length) return true; } -if (tokens[0] == "child") -{ -if (_kind != Kind::ToPrisoner) -{ -sendTextFrame("error: cmd=child kind=invalid"); -return false; -} -if (!_peer.expired()) -{ -sendTextFrame("error: cmd=child kind=invalid"); -return false; -} -if (tokens.count() != 3) -{ -sendTextFrame("error: cmd=child kind=syntax"); -return false; -} - -// child -> 0, sessionId -> 1, PID -> 2 -setId(tokens[1]); -_childId = tokens[2]; - -Log::info() << getName() << " Child jailId=" << _childId << ", sessionId=" << getId() << Log::end; -} -else if (_kind == Kind::ToPrisoner) +if (_kind == Kind::ToPrisoner) { // Message from child process to be forwarded to client. @@ -420,10 +395,6 @@ bool MasterProcessSession::_handleInput(const char *buffer, int length) return true; } -bool MasterProcessSession::haveSeparateProcess() -{ -return !_childId.empty(); -} bool MasterProcessSession::invalidateTiles(const char* /*buffer*/, int /*length*/, StringTokenizer& tokens) { int part, tilePosX, tilePosY, tileWidth, tileHeight; diff --git a/loolwsd/MasterProcessSession.hpp b/loolwsd/MasterProcessSession.hpp index f2049fe..c1b6dd6 100644 --- a/loolwsd/MasterProcessSession.hpp +++ b/loolwsd/MasterProcessSession.hpp @@ -25,8 +25,6 @@ public: std::shared_ptr docBroker); virtual ~MasterProcessSession(); -bool haveSeparateProcess(); - virtual bool getStatus(const char *buffer, int length) override; virtual bool getCommandV
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp loolwsd/LOOLWSD.cpp
loolwsd/LOOLKit.cpp | 14 +++--- loolwsd/LOOLWSD.cpp | 12 +--- 2 files changed, 20 insertions(+), 6 deletions(-) New commits: commit 8ef45a975e1ef950d4e754e43b82cda78f917847 Author: Ashod Nakashian Date: Sat Mar 12 18:12:40 2016 -0500 loolwsd: child URI now includes docKey Change-Id: I62b91fee98fd853c84c3c5cbb48e65e5c9788ef0 Reviewed-on: https://gerrit.libreoffice.org/23215 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 4fb6141..33aebe1 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #define LOK_USE_UNSTABLE_API #include @@ -310,10 +311,12 @@ public: Document(LibreOfficeKit *loKit, const std::string& jailId, + const std::string& docKey, const std::string& url) : _multiView(std::getenv("LOK_VIEW_CALLBACK")), _loKit(loKit), _jailId(jailId), +_docKey(docKey), _url(url), _loKitDocument(nullptr), _docPassword(""), @@ -404,7 +407,7 @@ public: HTTPClientSession cs("127.0.0.1", MASTER_PORT_NUMBER); cs.setTimeout(0); -HTTPRequest request(HTTPRequest::HTTP_GET, CHILD_URI + "sessionId=" + sessionId + "&jailId=" + _jailId); +HTTPRequest request(HTTPRequest::HTTP_GET, CHILD_URI + "sessionId=" + sessionId + "&jailId=" + _jailId + "&docKey=" + _docKey); HTTPResponse response; auto ws = std::make_shared(cs, request, response); @@ -734,6 +737,7 @@ private: const bool _multiView; LibreOfficeKit *_loKit; const std::string _jailId; +const std::string _docKey; const std::string _url; std::string _jailedUrl; @@ -1007,12 +1011,16 @@ void lokit_main(const std::string& childRoot, { const std::string& sessionId = tokens[1]; const unsigned intSessionId = Util::decodeId(sessionId); -const std::string& url = tokens[2]; +const std::string& docKey = tokens[2]; +std::string url; +Poco::URI::decode(docKey, url); Log::debug("Thread request for session [" + sessionId + "], url: [" + url + "]."); auto it = _documents.lower_bound(url); if (it == _documents.end()) -it = _documents.emplace_hint(it, url, std::make_shared(loKit, jailId, url)); +{ +it = _documents.emplace_hint(it, url, std::make_shared(loKit, jailId, docKey, url)); +} it->second->createSession(sessionId, intSessionId); isUsedKit = true; diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index 1e833d9..b295bb6 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -506,7 +506,8 @@ private: // Log::info("Cookie: " + cookies.get("PHPSESSID", "")); const auto uri = DocumentStoreManager::getUri(request.getURI()); -const auto docKey = uri.getPath(); +std::string docKey; +Poco::URI::encode(uri.getPath(), "", docKey); // Request a kit process for this doc. const std::string aMessage = "request " + id + " " + docKey + "\r\n"; @@ -609,6 +610,7 @@ public: const auto params = Poco::URI(request.getURI()).getQueryParameters(); std::string sessionId; std::string jailId; +std::string docKey; for (const auto& param : params) { if (param.first == "sessionId") @@ -619,16 +621,20 @@ public: { jailId = param.second; } +else if (param.first == "docKey") +{ +docKey = param.second; +} } -Log::debug("Child socket for SessionId: " + sessionId + ", jailId: " + jailId + " connected."); - thread_name += sessionId; if (prctl(PR_SET_NAME, reinterpret_cast(thread_name.c_str()), 0, 0, 0) != 0) Log::error("Cannot set thread name to " + thread_name + "."); Log::debug("Thread [" + thread_name + "] started."); +Log::debug("Child socket for SessionId: " + sessionId + ", jailId: " + jailId + + ", docKey: " + docKey + " connected."); auto ws = std::make_shared(request, response); auto session = std::make_shared(sessionId, LOOLSession::Kind::ToPrisoner, ws, nullptr); ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp loolwsd/Util.cpp loolwsd/Util.hpp
loolwsd/LOOLKit.cpp |5 +++-- loolwsd/Util.cpp| 17 - loolwsd/Util.hpp|3 ++- 3 files changed, 21 insertions(+), 4 deletions(-) New commits: commit 019aed134e17b69e615a5990eab8c471184973e9 Author: Ashod Nakashian Date: Sat Mar 12 10:15:45 2016 -0500 loolwsd: using random jailId Change-Id: Ie9501e4346a124994270ca1fac61869ed04b9b72 Reviewed-on: https://gerrit.libreoffice.org/23213 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 5414a26..4fb6141 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -414,7 +414,7 @@ public: [this](const std::string& id, const std::string& uri, const std::string& docPassword, bool isDocPasswordProvided) { return onLoad(id, uri, docPassword, isDocPasswordProvided); }, [this](const std::string& id) { onUnload(id); }); // child -> 0, sessionId -> 1, PID -> 2 -const std::string hello("child " + sessionId + " " + std::to_string(Process::id())); +const std::string hello("child " + sessionId + " " + _jailId); session->sendTextFrame(hello); auto thread = std::make_shared(session, ws); @@ -764,6 +764,7 @@ void lokit_main(const std::string& childRoot, #ifdef LOOLKIT_NO_MAIN // Reinitialize logging when forked. Log::initialize("kit"); +Util::rng::reseed(); #endif struct pollfd pollPipeBroker; @@ -782,7 +783,7 @@ void lokit_main(const std::string& childRoot, std::map> _documents; -static const std::string jailId = std::to_string(Process::id()); +static const std::string jailId = Util::encodeId(Util::rng::getNext()); static const std::string process_name = "loolkit"; if (prctl(PR_SET_NAME, reinterpret_cast(process_name.c_str()), 0, 0, 0) != 0) diff --git a/loolwsd/Util.cpp b/loolwsd/Util.cpp index 7485a9e..5fc9a2a 100644 --- a/loolwsd/Util.cpp +++ b/loolwsd/Util.cpp @@ -65,7 +65,22 @@ namespace rng { static std::random_device _rd; static std::mutex _rngMutex; -static std::mt19937_64 _rng = std::mt19937_64(_rd()); + +// Create the prng with a random-device for seed. +// If we don't have a hardware random-device, we will get the same seed. +// In that case we are better off with an arbitrary, but changing, seed. +static std::mt19937_64 _rng = std::mt19937_64(_rd.entropy() +? _rd() +: (clock() + getpid())); + +// A new seed is used to shuffle the sequence. +// N.B. Always reseed after getting forked! +void reseed() +{ +_rng.seed(_rd.entropy() ? _rd() : (clock() + getpid())); +} + +// Returns a new random number. unsigned getNext() { std::unique_lock lock(_rngMutex); diff --git a/loolwsd/Util.hpp b/loolwsd/Util.hpp index 1e6e515..2e83ea8 100644 --- a/loolwsd/Util.hpp +++ b/loolwsd/Util.hpp @@ -50,7 +50,8 @@ namespace Util { namespace rng { - unsigned getNext(); +void reseed(); +unsigned getNext(); } /// Encode an integral ID into a string, with padding support. ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp |5 + 1 file changed, 5 insertions(+) New commits: commit 2103fe2515b7c71aff546dc00fe8a46721abdfa2 Author: Tor Lillqvist Date: Thu Mar 3 18:35:48 2016 +0200 Revert "We use a recursive mutex, so no need to drop and re-take around documentLoad()" Turns out the callbacks from documentLoad() are in general done on another thread, not necessarily the same one that did the documentLoad() call. Not sure why it happened to be the same thread for me, but oh well. Need to fix the problem described in 3671abf89b376555394b22bfee25d450e7eff5f6 in some other way then. This reverts commit 2fab7574626919d66c637f40302cb00e8d280b3f. diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 7942436..31b659d 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -620,6 +620,9 @@ private: LOK_FEATURE_DOCUMENT_PASSWORD_TO_MODIFY); } +// documentLoad will trigger callback, which needs to take the lock. +lock.unlock(); + // Save the provided password with us and the jailed url _isDocPasswordProvided = isDocPasswordProvided; _docPassword = docPassword; @@ -649,6 +652,8 @@ private: return nullptr; } Log::info("documentLoad() returned"); +// Retake the lock. +lock.lock(); if (_multiView) { ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp |2 +- 1 file changed, 1 insertion(+), 1 deletion(-) New commits: commit bf63df227b63c7dcdbdd4439c90d0c37939d8261 Author: Tor Lillqvist Date: Wed Mar 2 16:41:46 2016 +0200 The payload can be null It is always null at least for LOK_CALLBACK_STATUS_INDICATOR_FINISH. diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index e7cf26b..31b659d 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -527,7 +527,7 @@ private: Document* self = reinterpret_cast(pData); Log::trace() << "Callback " << KitCallbackTypeToString(nType) - << " [" << pPayload << "]." << Log::end; + << " [" << (pPayload ? pPayload : "") << "]." << Log::end; if (self) { ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp |7 ++- 1 file changed, 6 insertions(+), 1 deletion(-) New commits: commit 38ddcf5243276bab51b9c1ccbe15e1821f05966f Author: Tor Lillqvist Date: Wed Mar 2 13:12:27 2016 +0200 Don't log the CR LF at the end of a response diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index ca340d6..e7cf26b 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -1010,8 +1010,13 @@ void lokit_main(const std::string& childRoot, response += "bad \r\n"; } -Log::trace("KitToBroker: " + response); Util::writeFIFO(writerBroker, response); + +// Don't log the CR LF at end +assert(response.length() > 2); +assert(response[response.length()-1] == '\n'); +assert(response[response.length()-2] == '\r'); +Log::trace("KitToBroker: " + response.substr(0, response.length()-2)); message.clear(); } } ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 12 +++- 1 file changed, 11 insertions(+), 1 deletion(-) New commits: commit 730ec991947a29fdd409afe23f12f650452737dc Author: Henry Castro Date: Sun Feb 21 08:10:30 2016 -0400 loolwsd: ensure lokit process exited successfully after close the document and views diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 248813c..552a48c 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -769,6 +769,7 @@ void lokit_main(const std::string& childRoot, struct pollfd pollPipeBroker; ssize_t bytes = -1; int ready = 0; +bool isDirtyKit = false; char buffer[READ_BUFFER_SIZE]; char* start = nullptr; char* end = nullptr; @@ -932,6 +933,9 @@ void lokit_main(const std::string& childRoot, { it = (it->second->canDiscard() ? _documents.erase(it) : ++it); } + +if (isDirtyKit && _documents.empty()) +TerminationFlag = true; } else if (ready < 0) @@ -982,7 +986,12 @@ void lokit_main(const std::string& childRoot, it = (it->second->canDiscard() ? _documents.erase(it) : ++it); } -if (tokens[0] == "query" && tokens.count() > 1) +if (isDirtyKit && _documents.empty()) +{ +TerminationFlag = true; +response += "down \r\n"; +} +else if (tokens[0] == "query" && tokens.count() > 1) { if (tokens[1] == "url") { @@ -1009,6 +1018,7 @@ void lokit_main(const std::string& childRoot, it = _documents.emplace_hint(it, url, std::make_shared(loKit, jailId, url)); it->second->createSession(sessionId, intSessionId); +isDirtyKit = true; response += "ok \r\n"; } else ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 26 +++--- 1 file changed, 19 insertions(+), 7 deletions(-) New commits: commit b646fca95d350dcacaf8d698a2bd1becf2b00444 Author: Henry Castro Date: Sun Feb 21 07:57:58 2016 -0400 loolwsd: add lokit iddle maintenance time out diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 95a80d4..248813c 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -768,6 +768,7 @@ void lokit_main(const std::string& childRoot, struct pollfd pollPipeBroker; ssize_t bytes = -1; +int ready = 0; char buffer[READ_BUFFER_SIZE]; char* start = nullptr; char* end = nullptr; @@ -923,7 +924,17 @@ void lokit_main(const std::string& childRoot, pollPipeBroker.events = POLLIN; pollPipeBroker.revents = 0; -if (poll(&pollPipeBroker, 1, POLL_TIMEOUT_MS) < 0) +ready = poll(&pollPipeBroker, 1, POLL_TIMEOUT_MS); +if (ready == 0) +{ +// time out maintenance +for (auto it = _documents.cbegin(); it != _documents.cend(); ) +{ +it = (it->second->canDiscard() ? _documents.erase(it) : ++it); +} +} +else +if (ready < 0) { Log::error("Failed to poll pipe [" + pipe + "]."); continue; @@ -965,15 +976,16 @@ void lokit_main(const std::string& childRoot, response = std::to_string(Process::id()) + " "; Log::trace("Recv: " + message); + +for (auto it = _documents.cbegin(); it != _documents.cend(); ) +{ +it = (it->second->canDiscard() ? _documents.erase(it) : ++it); +} + if (tokens[0] == "query" && tokens.count() > 1) { if (tokens[1] == "url") { -for (auto it = _documents.cbegin(); it != _documents.cend(); ) -{ -it = (it->second->canDiscard() ? _documents.erase(it) : ++it); -} - if (_documents.empty()) { response += "empty \r\n"; @@ -1001,7 +1013,7 @@ void lokit_main(const std::string& childRoot, } else { -response = "bad \r\n"; +response += "bad \r\n"; } Log::trace("KitToBroker: " + response); ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) New commits: commit f72915680636810db4a1de72aef47a5104357080 Author: Pranav Kant Date: Sun Feb 21 12:17:01 2016 +0530 loolwsd: Fix misplaced break statement Probably due to merge conflicts, it ended up in a wrong place. Change-Id: Ia32e18149d99e901ceaa47a4e984f9ca818d0619 diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index c8355a6..95a80d4 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -560,12 +560,12 @@ private: self->setDocumentPassword(nType); break; } -} -// Ideally, there would be only one *live* connection at this point of time -// So, just get the first running one and break out. -// TODO: Find a better way to find the correct connection. -break; +// Ideally, there would be only one *live* connection at this point of time +// So, just get the first running one and break out. +// TODO: Find a better way to find the correct connection. +break; +} } } } ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 67 +++- 1 file changed, 30 insertions(+), 37 deletions(-) New commits: commit 631ae0f11fb863a2ba9bbcc279c83905af8bba96 Author: Pranav Kant Date: Sun Feb 7 22:08:48 2016 +0530 loolwsd: Get the first *live* connection Sometimes there are situations when `connection` map is filled with dead sessions. We don't want to deal with those dead ones. Change-Id: I00dda77c39b5adbba69421eace0be0159e02505c Reviewed-on: https://gerrit.libreoffice.org/22207 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 3694d42..703e30b 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -496,48 +496,41 @@ private: static void KitCallback(int nType, const char* pPayload, void* pData) { Document* self = reinterpret_cast(pData); +Log::trace() << "Callback " + << KitCallbackTypeToString(nType) + << " [" << pPayload << "]." << Log::end; + if (self) { std::unique_lock lock(self->_mutex); - -// Ideally, there would be only one connection at this point of time -const auto& it = self->_connections.begin(); - -if (!it->second->isRunning()) -Log::error() << "Error: Connection died unexpectedly" << Log::end; - -auto session = it->second->getSession(); -auto sessionLock = session->getLock(); - -Log::trace() << "Callback [" << session->getViewId() << "] " - << KitCallbackTypeToString(nType) - << " [" << pPayload << "]." << Log::end; - -if (session->isDisconnected()) -{ -Log::trace("Skipping callback on disconnected session " + session->getName()); -return; -} -else if (session->isInactive()) +for (auto& it: self->_connections) { -Log::trace("Skipping callback on inactive session " + session->getName()); -return; -} +if (it.second->isRunning()) +{ +auto session = it.second->getSession(); +auto sessionLock = session->getLock(); -switch (nType) -{ -case LOK_CALLBACK_STATUS_INDICATOR_START: -session->sendTextFrame("statusindicatorstart:"); -break; -case LOK_CALLBACK_STATUS_INDICATOR_SET_VALUE: -session->sendTextFrame("statusindicatorsetvalue: " + std::string(pPayload)); -break; -case LOK_CALLBACK_STATUS_INDICATOR_FINISH: -session->sendTextFrame("statusindicatorfinish:"); -break; -case LOK_CALLBACK_DOCUMENT_PASSWORD: -case LOK_CALLBACK_DOCUMENT_PASSWORD_TO_MODIFY: -session->setDocumentPassword(nType); +switch (nType) +{ +case LOK_CALLBACK_STATUS_INDICATOR_START: +session->sendTextFrame("statusindicatorstart:"); +break; +case LOK_CALLBACK_STATUS_INDICATOR_SET_VALUE: +session->sendTextFrame("statusindicatorsetvalue: " + std::string(pPayload)); +break; +case LOK_CALLBACK_STATUS_INDICATOR_FINISH: +session->sendTextFrame("statusindicatorfinish:"); +break; +case LOK_CALLBACK_DOCUMENT_PASSWORD: +case LOK_CALLBACK_DOCUMENT_PASSWORD_TO_MODIFY: +session->setDocumentPassword(nType); +break; +} +} + +// Ideally, there would be only one *live* connection at this point of time +// So, just get the first running one and break out. +// TODO: Find a better way to find the correct connection. break; } } ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 29 - 1 file changed, 16 insertions(+), 13 deletions(-) New commits: commit 7ecde2342246274d4f5564fd13511856e7533921 Author: Pranav Kant Date: Sun Feb 7 14:38:03 2016 +0530 loolwsd: Remove superfluous registration of callback Our DocumentCallback is smart enough which checks all the running connections, and send the callback notification to all of them. Registering the callback only during the first loadDocument call should be enough. Change-Id: I82bcb9525814dae14def3bfb6c088337d0d0ea3c Reviewed-on: https://gerrit.libreoffice.org/22202 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 9c55ff3..00847da 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -516,10 +516,12 @@ private: if (_loKitDocument == nullptr) { +// This is the first time we are loading the document Log::info("Loading new document from URI: [" + uri + "] for session [" + sessionId + "]."); if ( LIBREOFFICEKIT_HAS(_loKit, registerCallback)) { +// TODO: Separate the global callback from document callback _loKit->pClass->registerCallback(_loKit, DocumentCallback, this); _loKit->pClass->setOptionalFeatures(_loKit, LOK_FEATURE_DOCUMENT_PASSWORD | LOK_FEATURE_DOCUMENT_PASSWORD_TO_MODIFY); @@ -527,6 +529,7 @@ private: // documentLoad will trigger callback, which needs to take the lock. lock.unlock(); + if ((_loKitDocument = _loKit->pClass->documentLoad(_loKit, uri.c_str())) == nullptr) { Log::error("Failed to load: " + uri + ", error: " + _loKit->pClass->getError(_loKit)); @@ -535,22 +538,22 @@ private: // Retake the lock. lock.lock(); -} -if (_multiView) -{ -Log::info("Loading view to document from URI: [" + uri + "] for session [" + sessionId + "]."); -const auto viewId = _loKitDocument->pClass->createView(_loKitDocument); +if (_multiView) +{ +Log::info("Loading view to document from URI: [" + uri + "] for session [" + sessionId + "]."); +const auto viewId = _loKitDocument->pClass->createView(_loKitDocument); -_loKitDocument->pClass->registerCallback(_loKitDocument, ViewCallback, reinterpret_cast(intSessionId)); +_loKitDocument->pClass->registerCallback(_loKitDocument, ViewCallback, reinterpret_cast(intSessionId)); -Log::info() << "Document [" << _url << "] view [" -<< viewId << "] loaded, leaving " -<< (_clientViews + 1) << " views." << Log::end; -} -else -{ -_loKitDocument->pClass->registerCallback(_loKitDocument, DocumentCallback, this); +Log::info() << "Document [" << _url << "] view [" +<< viewId << "] loaded, leaving " +<< (_clientViews + 1) << " views." << Log::end; +} +else +{ +_loKitDocument->pClass->registerCallback(_loKitDocument, DocumentCallback, this); +} } ++_clientViews; ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 80 ++-- 1 file changed, 40 insertions(+), 40 deletions(-) New commits: commit 10070b11a920372e1869afb7a141e1de9bc04b42 Author: Henry Castro Date: Thu Feb 18 12:20:12 2016 -0400 loolwsd: fixes coding style naming convention in LOOLKit.cpp diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 4043d76..fb4e641 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -604,11 +604,11 @@ void lokit_main(const std::string& childRoot, Log::initialize("kit"); #endif -struct pollfd aPoll; -ssize_t nBytes = -1; -char aBuffer[READ_BUFFER_SIZE]; -char* pStart = nullptr; -char* pEnd = nullptr; +struct pollfd pollPipeBroker; +ssize_t bytes = -1; +char buffer[READ_BUFFER_SIZE]; +char* start = nullptr; +char* end = nullptr; assert(!childRoot.empty()); assert(!sysTemplate.empty()); @@ -624,6 +624,7 @@ void lokit_main(const std::string& childRoot, #ifdef __linux if (prctl(PR_SET_NAME, reinterpret_cast(process_name.c_str()), 0, 0, 0) != 0) Log::error("Cannot set process name to " + process_name + "."); + Util::setTerminationSignals(); Util::setFatalSignals(); #endif @@ -642,7 +643,7 @@ void lokit_main(const std::string& childRoot, int writerBroker; int readerBroker; -if ( (readerBroker = open(pipe.c_str(), O_RDONLY) ) < 0 ) +if ((readerBroker = open(pipe.c_str(), O_RDONLY) ) < 0) { Log::error("Error: failed to open pipe [" + pipe + "] read only."); exit(Application::EXIT_SOFTWARE); @@ -650,7 +651,7 @@ void lokit_main(const std::string& childRoot, const Path pipePath = Path::forDirectory(childRoot + Path::separator() + FIFO_PATH); const std::string pipeBroker = Path(pipePath, FIFO_BROKER).toString(); -if ( (writerBroker = open(pipeBroker.c_str(), O_WRONLY) ) < 0 ) +if ((writerBroker = open(pipeBroker.c_str(), O_WRONLY) ) < 0) { Log::error("Error: failed to open pipe [" + FIFO_BROKER + "] write only."); exit(Application::EXIT_SOFTWARE); @@ -749,59 +750,59 @@ void lokit_main(const std::string& childRoot, Log::info("loolkit [" + std::to_string(Process::id()) + "] is ready."); -std::string aResponse; -std::string aMessage; +std::string response; +std::string message; while (!TerminationFlag) { -if ( pStart == pEnd ) +if (start == end) { -aPoll.fd = readerBroker; -aPoll.events = POLLIN; -aPoll.revents = 0; +pollPipeBroker.fd = readerBroker; +pollPipeBroker.events = POLLIN; +pollPipeBroker.revents = 0; -if (poll(&aPoll, 1, POLL_TIMEOUT_MS) < 0) +if (poll(&pollPipeBroker, 1, POLL_TIMEOUT_MS) < 0) { Log::error("Failed to poll pipe [" + pipe + "]."); continue; } else -if (aPoll.revents & (POLLIN | POLLPRI)) +if (pollPipeBroker.revents & (POLLIN | POLLPRI)) { -nBytes = Util::readFIFO(readerBroker, aBuffer, sizeof(aBuffer)); -if (nBytes < 0) +bytes = Util::readFIFO(readerBroker, buffer, sizeof(buffer)); +if (bytes < 0) { -pStart = pEnd = nullptr; +start = end = nullptr; Log::error("Error reading message from pipe [" + pipe + "]."); continue; } -pStart = aBuffer; -pEnd = aBuffer + nBytes; +start = buffer; +end = buffer + bytes; } else -if (aPoll.revents & (POLLERR | POLLHUP)) +if (pollPipeBroker.revents & (POLLERR | POLLHUP)) { Log::error("Broken pipe [" + pipe + "] with broker."); break; } } -if ( pStart != pEnd ) +if (start != end) { -char aChar = *pStart++; -while (pStart != pEnd && aChar != '\r' && aChar != '\n') +char byteChar = *start++; +while (start != end && byteChar != '\r' && byteChar != '\n') { -aMessage += aChar; -aChar = *pStart++; +message += byteChar; +byteChar = *start++; } -if ( aChar == '\r' && *pStart == '\n') +if (byteChar == '\r' && *start == '\n') { -pStart++; -StringToken
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp loolwsd/Util.cpp
loolwsd/LOOLKit.cpp |2 -- loolwsd/Util.cpp|2 -- 2 files changed, 4 deletions(-) New commits: commit 45754cc36c7b087700c238d6e9d7d05b5cc04f2f Author: Henry Castro Date: Sun Feb 14 23:07:40 2016 -0400 loolwsd: remove unused TerminationState diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 80a763b..8089bd2 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -835,12 +835,10 @@ void lokit_main(const std::string& childRoot, Log::error() << exc.name() << ": " << exc.displayText() << (exc.nested() ? " (" + exc.nested()->displayText() + ")" : "") << Log::end; -TerminationState = LOOLState::LOOL_ABNORMAL; } catch (const std::exception& exc) { Log::error(std::string("Exception: ") + exc.what()); -TerminationState = LOOLState::LOOL_ABNORMAL; } Log::debug("Destroying documents."); diff --git a/loolwsd/Util.cpp b/loolwsd/Util.cpp index e4ae391..1685d38 100644 --- a/loolwsd/Util.cpp +++ b/loolwsd/Util.cpp @@ -60,7 +60,6 @@ extern "C" } } -volatile LOOLState TerminationState = LOOLState::LOOL_RUNNING; volatile bool TerminationFlag = false; namespace Util @@ -424,7 +423,6 @@ namespace Util // If we are signaled while having that lock, // logging again will deadlock on it. TerminationFlag = true; -TerminationState = ( aSignal == SIGTERM ? LOOLState::LOOL_ABNORMAL : LOOLState::LOOL_STOPPING ); Log::info() << "Termination signal received: " << Util::signalName(aSignal) << " " ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp |2 +- 1 file changed, 1 insertion(+), 1 deletion(-) New commits: commit 93fdcb34c48c0a877c76175892e85b32e97cfccf Author: Pranav Kant Date: Sun Feb 7 14:48:32 2016 +0530 loolwsd: Do not unload without a successfull load A load document operation may fail, for example, when user enters a wrong password or no password. In such cases ToPrisoner sends a disconnect to child. Child do not need to take any steps in this case, such as, decrementing the view counter, because nothing was loaded. Change-Id: Ib71f871aa1728c6355563362987800dece1679d3 Reviewed-on: https://gerrit.libreoffice.org/22203 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 2b47a0b..80a763b 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -558,7 +558,7 @@ private: const unsigned intSessionId = Util::decodeId(sessionId); const auto it = _connections.find(intSessionId); -if (it == _connections.end() || !it->second) +if (it == _connections.end() || !it->second || !_loKitDocument) { // Nothing to do. return; ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 22 +++--- 1 file changed, 15 insertions(+), 7 deletions(-) New commits: commit 42abb3b1a73d7aeb0280389ca2c28bb041de2039 Author: Henry Castro Date: Sun Feb 14 14:32:55 2016 -0400 loolwsd: websocket shutdown receive diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 5655a8c..6f1fc63 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #define LOK_USE_UNSTABLE_API #include @@ -338,17 +339,24 @@ public: // Destroy all connections and views. for (auto aIterator : _connections) { -if (TerminationState == LOOLState::LOOL_ABNORMAL) +try { // stop all websockets -std::shared_ptr ws = aIterator.second->getWebSocket(); -if ( ws ) -ws->shutdownReceive(); +if (aIterator.second->isRunning()) +{ +std::shared_ptr ws = aIterator.second->getWebSocket(); +if ( ws ) +{ +ws->shutdownReceive(); +aIterator.second->join(); +} +} } -else +catch(Poco::Net::NetException& exc) { -// wait until loolwsd close all websockets -aIterator.second->join(); +Log::error() << "Error: " << exc.displayText() + << (exc.nested() ? " (" + exc.nested()->displayText() + ")" : "") + << Log::end; } } ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp |4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) New commits: commit f5c163e6daf3638a2fec2f65aa2372f6a96b4d36 Author: Henry Castro Date: Sun Feb 14 14:39:02 2016 -0400 loolwsd: avoid deadlock with mutex and join diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 6f1fc63..2b47a0b 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -325,8 +325,6 @@ public: ~Document() { -std::unique_lock lock(_mutex); - Log::info("~Document dtor for url [" + _url + "] on child [" + _jailId + "]. There are " + std::to_string(_clientViews) + " views."); @@ -360,6 +358,8 @@ public: } } +std::unique_lock lock(_mutex); + // Destroy all connections and views. _connections.clear(); ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp |2 +- 1 file changed, 1 insertion(+), 1 deletion(-) New commits: commit 5a31f99178e62e785eed2055e7cba2120eb2cebb Author: Pranav Kant Date: Sun Feb 7 16:21:10 2016 +0530 loolwsd: Thread name should not be static ... as we can have multiple connections for same document. Change-Id: Ic213299d6a4ba703f1e27cf252f3a10209f08148 Reviewed-on: https://gerrit.libreoffice.org/22204 Reviewed-by: Henry Castro Tested-by: Henry Castro diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 763e21d..3ed6b3e 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -118,7 +118,7 @@ public: void run() override { -static const std::string thread_name = "kit_ws_" + _session->getId(); +const std::string thread_name = "kit_ws_" + _session->getId(); #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 + "."); ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 18 ++ 1 file changed, 10 insertions(+), 8 deletions(-) New commits: commit 647d7c778390625798dd83f470ac307d6e59803d Author: Henry Castro Date: Tue Feb 2 20:07:15 2016 -0400 loolwsd: first, establish pipe connection diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index f57c7ad..763e21d 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -530,13 +530,7 @@ void lokit_main(const std::string &loSubPath, const std::string& jailId, const s #else ("/" + loSubPath + "/program"); #endif - -LibreOfficeKit* loKit(lok_init_2(instdir_path.c_str(), "file:///user")); -if (loKit == nullptr) -{ -Log::error("Error: LibreOfficeKit initialization failed. Exiting."); -exit(Application::EXIT_SOFTWARE); -} +LibreOfficeKit* loKit = nullptr; try { @@ -555,6 +549,13 @@ void lokit_main(const std::string &loSubPath, const std::string& jailId, const s exit(Application::EXIT_SOFTWARE); } +loKit = lok_init_2(instdir_path.c_str(), "file:///user"); +if (loKit == nullptr) +{ +Log::error("Error: LibreOfficeKit initialization failed. Exiting."); +exit(Application::EXIT_SOFTWARE); +} + Log::info("loolkit [" + std::to_string(Process::id()) + "] is ready."); std::string aResponse; @@ -677,7 +678,8 @@ void lokit_main(const std::string &loSubPath, const std::string& jailId, const s // Destroy LibreOfficeKit Log::debug("Destroying LibreOfficeKit."); -loKit->pClass->destroy(loKit); +if (loKit) +loKit->pClass->destroy(loKit); Log::info("Process [" + process_name + "] finished."); } ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp |2 -- 1 file changed, 2 deletions(-) New commits: commit 1ff52f2e2c1c78c2ab32d6b72fcd587e0b04d99d Author: Henry Castro Date: Mon Jan 25 11:41:24 2016 -0400 loolwsd: remove unnecessary Poco thread default pool diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 6764c29..0c6f43f 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -650,8 +650,6 @@ void lokit_main(const std::string &loSubPath, const std::string& jailId, const s } } -Poco::ThreadPool::defaultPool().joinAll(); - close(writerBroker); close(readerBroker); } ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 30 -- 1 file changed, 20 insertions(+), 10 deletions(-) New commits: commit 4dc9fa7eb7563ff1d2013ad6d3bd22d3512f0cf9 Author: Ashod Nakashian Date: Fri Jan 22 09:27:03 2016 -0500 loolwsd: prevent deadlock when purging sessions Change-Id: I293e28674ed721741fa0afc57b37a636833d2e0e Reviewed-on: https://gerrit.libreoffice.org/21750 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index e474efa..5fac3eb 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -581,21 +581,31 @@ public: /// the remaining number of clients. size_t purgeSessions() { -std::unique_lock lock(_mutex); - -for (auto it =_connections.cbegin(); it != _connections.cend(); ) +std::vector> deadSessions; { -if (!it->second->isRunning()) -{ -onUnload(it->second->getSession()->getId()); -it = _connections.erase(it); -} -else +std::unique_lock lock(_mutex); + +for (auto it =_connections.cbegin(); it != _connections.cend(); ) { -++it; +if (!it->second->isRunning()) +{ +deadSessions.push_back(it->second->getSession()); +it = _connections.erase(it); +} +else +{ +++it; +} } } +// Don't destroy sessions while holding our lock. +// We may deadlock if a session is waiting on us +// during callback initiated while handling a command +// and the dtor tries to take its lock (which is taken). +deadSessions.clear(); + +std::unique_lock lock(_mutex); return _connections.size(); } ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 51 +-- 1 file changed, 21 insertions(+), 30 deletions(-) New commits: commit 49d7c0e17f3f0b027a932f72295ef83995cc1232 Author: Ashod Nakashian Date: Tue Jan 19 20:31:36 2016 -0500 loolwsd: improved lokit callback notification dispatcher Change-Id: I88abad83a3d06eb530200d921ef25b68465b82b6 Reviewed-on: https://gerrit.libreoffice.org/21675 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 0883b48..b779180 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -264,48 +264,40 @@ public: while (!_stop && !TerminationFlag) { Notification::Ptr aNotification(_queue.waitDequeueNotification()); -if (!TerminationFlag && aNotification) +if (!_stop && !TerminationFlag && aNotification) { CallBackNotification::Ptr aCallBackNotification = aNotification.cast(); -if (aCallBackNotification) +assert(aCallBackNotification); + +const auto nType = aCallBackNotification->m_nType; +try { -const auto nType = aCallBackNotification->m_nType; -try -{ -callback(nType, aCallBackNotification->m_aPayload, aCallBackNotification->m_pSession); -} -catch (const Exception& exc) -{ -Log::error() << "Error while handling callback [" << callbackTypeToString(nType) << "]. " - << exc.displayText() - << (exc.nested() ? " (" + exc.nested()->displayText() + ")" : "") - << Log::end; -} -catch (const std::exception& exc) -{ -Log::error("Error while handling callback [" + callbackTypeToString(nType) + "]. " + - std::string("Exception: ") + exc.what()); -} -catch (...) -{ -Log::error("Unexpected Exception while handling callback [" + callbackTypeToString(nType) + "]."); -} +callback(nType, aCallBackNotification->m_aPayload, aCallBackNotification->m_pSession); +} +catch (const Exception& exc) +{ +Log::error() << "Error while handling callback [" << callbackTypeToString(nType) << "]. " + << exc.displayText() + << (exc.nested() ? " (" + exc.nested()->displayText() + ")" : "") + << Log::end; +} +catch (const std::exception& exc) +{ +Log::error("Error while handling callback [" + callbackTypeToString(nType) + "]. " + + std::string("Exception: ") + exc.what()); } } -else break; +else +break; } Log::debug("Thread [" + thread_name + "] finished."); } -void wakeUpAll() -{ -_queue.wakeUpAll(); -} - void stop() { _stop = true; +_queue.wakeUpAll(); } private: @@ -491,7 +483,6 @@ public: // Wait for the callback worker to finish. _callbackWorker.stop(); -_callbackWorker.wakeUpAll(); _callbackThread.join(); // Flag all connections to stop. ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 12 ++-- 1 file changed, 6 insertions(+), 6 deletions(-) New commits: commit 54d5138537135c4dbf7f8b76b0de40e8be4e330e Author: Ashod Nakashian Date: Tue Jan 19 19:38:13 2016 -0500 loolwsd: proper destruction of LibreOfficeKit instance Change-Id: If39b0d534eb93044383766a51f26faac398c834e Reviewed-on: https://gerrit.libreoffice.org/21673 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index a010383..0883b48 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -784,9 +784,8 @@ void lokit_main(const std::string &loSubPath, const std::string& jailId, const s ("/" + loSubPath + "/program"); #endif -std::unique_ptr loKit(lok_init_2(instdir_path.c_str(), "file:///user")); - -if (!loKit) +LibreOfficeKit* loKit(lok_init_2(instdir_path.c_str(), "file:///user")); +if (loKit == nullptr) { Log::error("Error: LibreOfficeKit initialization failed. Exiting."); exit(-1); @@ -890,7 +889,7 @@ void lokit_main(const std::string &loSubPath, const std::string& jailId, const s Log::debug("Thread request for session [" + sessionId + "], url: [" + url + "]."); auto it = _documents.lower_bound(url); if (it == _documents.end()) -it = _documents.emplace_hint(it, url, std::make_shared(loKit.get(), jailId, url)); +it = _documents.emplace_hint(it, url, std::make_shared(loKit, jailId, url)); it->second->createSession(sessionId, intSessionId); aResponse += "ok \r\n"; @@ -925,11 +924,12 @@ void lokit_main(const std::string &loSubPath, const std::string& jailId, const s TerminationState = LOOLState::LOOL_ABNORMAL; } +Log::debug("Destroying documents."); _documents.clear(); // Destroy LibreOfficeKit -loKit->pClass->destroy(loKit.get()); -loKit.release(); +Log::debug("Destroying LibreOfficeKit."); +loKit->pClass->destroy(loKit); Log::info("Process [" + process_name + "] finished."); } ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 59 1 file changed, 41 insertions(+), 18 deletions(-) New commits: commit 558dfd40e0f5a50c225a13ac859eb32466ccb384 Author: Ashod Nakashian Date: Wed Jan 13 19:26:23 2016 -0500 loolwsd: unloading of disconnected documents Documents that do not have any client connections to are unloaded. Currently we do not check for saved state of the document before unloading. Change-Id: I0f4f2ec1a7ddb15262833fe3d4ab73af16a2a959 Reviewed-on: https://gerrit.libreoffice.org/21472 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 30adb6b..cf8aef8 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -396,6 +396,9 @@ public: } } while (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE && !_stop); +Log::debug() << "Finishing " << thread_name << ". stop " << _stop + << ", payload size: " << n + << ", flags: " << std::hex << flags << Log::end; queue.clear(); queue.put("eof"); @@ -403,7 +406,6 @@ public: // We should probably send the Client some sensible message and reason. _session->sendTextFrame("eof"); -_session.reset(); } catch (const Exception& exc) { @@ -459,7 +461,7 @@ public: ~Document() { -std::unique_lock lock(_mutex); +std::unique_lock lock(_mutex); Log::info("~Document dtor for url [" + _url + "] on child [" + _jailId + "]. There are " + std::to_string(_clientViews) + " views."); @@ -505,7 +507,7 @@ public: void createSession(const std::string& sessionId, const unsigned intSessionId) { -std::unique_lock lock(_mutex); +std::unique_lock lock(_mutex); const auto& it = _connections.find(intSessionId); if (it != _connections.end()) @@ -556,26 +558,41 @@ public: Log::debug("Connections: " + std::to_string(_connections.size())); } -void purgeSessions() +/// Purges dead connections and returns +/// the remaining number of clients. +size_t purgeSessions() { -std::unique_lock lock(_mutex); +std::unique_lock lock(_mutex); for (auto it =_connections.cbegin(); it != _connections.cend(); ) { if (!it->second->isRunning()) { -_connections.erase(it++); -continue; +onUnload(it->second->getSession()->getId()); +it = _connections.erase(it); +} +else +{ +++it; } -it++; } + +return _connections.size(); } +/// Returns true if at least one *live* connection exists. +/// Does not consider user activity, just socket status. bool hasConnections() { -std::unique_lock lock(_mutex); +return purgeSessions() > 0; +} -return !_connections.empty(); +/// Returns true if there is no activity and +/// the document is saved. +bool canDiscard() +{ +//TODO: Implement proper time-out on inactivity. +return !hasConnections(); } private: @@ -593,7 +610,7 @@ private: Document* self = reinterpret_cast(pData); if (self) { -std::unique_lock lock(self->_mutex); +std::unique_lock lock(self->_mutex); for (auto& it: self->_connections) { @@ -616,7 +633,7 @@ private: Log::info("Session " + sessionId + " is loading. " + std::to_string(_clientViews) + " views loaded."); const unsigned intSessionId = Util::decodeId(sessionId); -std::unique_lock lock(_mutex); +std::unique_lock lock(_mutex); const auto it = _connections.find(intSessionId); if (it == _connections.end() || !it->second) @@ -666,19 +683,18 @@ private: void onUnload(const std::string& sessionId) { -Log::info("Session " + sessionId + " is unloading. " + std::to_string(_clientViews - 1) + " views left."); -const unsigned intSessionId = Util::decodeId(sessionId); - -std::unique_lock lock(_mutex); +std::unique_lock lock(_mutex); +const unsigned intSessionId = Util::decodeId(sessionId); const auto it = _connections.find(intSessionId); if (it == _connections.end() || !it->second) { -Log::error("Cannot find session [" + sessionId + "] which decoded to " + std::to_string(intSessionId)); +// Nothing to do. return; } --_clientViews; +Log::info("Session " + sessionId + " is unloading. " + std::to_string(_clientViews) + " views will remain."); if (_mul
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp loolwsd/LOOLWSD.cpp
loolwsd/LOOLKit.cpp | 76 +--- loolwsd/LOOLWSD.cpp |3 +- 2 files changed, 34 insertions(+), 45 deletions(-) New commits: commit c2af36d0ef99b509bd5087704c7afa8e61721ce7 Author: Ashod Nakashian Date: Tue Jan 12 17:47:50 2016 -0500 loolwsd: simplified Connection Change-Id: Ia7ff0d4b636513ce1b08641bb6db85c97ee5c2f9 Reviewed-on: https://gerrit.libreoffice.org/21468 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 2fa260d..2093825 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -316,30 +316,22 @@ private: class Connection: public Runnable { public: -Connection(LibreOfficeKit *loKit, LibreOfficeKitDocument *loKitDocument, - const std::string& jailId, const std::string& sessionId, - std::function onLoad, - std::function onUnload) : -_loKit(loKit), -_loKitDocument(loKitDocument), -_jailId(jailId), -_sessionId(sessionId), -_stop(false), -_onLoad(onLoad), -_onUnload(onUnload) +Connection(std::shared_ptr session, + std::shared_ptr ws) : +_session(session), +_ws(ws), +_stop(false) { -Log::info("Connection ctor in child: " + _jailId + ", thread: " + _sessionId); +Log::info("Connection ctor in child for " + _session->getId()); } ~Connection() { -Log::info("~Connection dtor in child: " + _jailId + ", thread: " + _sessionId); +Log::info("~Connection dtor in child for " + _session->getId()); stop(); } -const std::string& getSessionId() const { return _sessionId; } std::shared_ptr getWebSocket() const { return _ws; } - std::shared_ptr getSession() { return _session; } void start() @@ -364,7 +356,7 @@ public: void run() override { -static const std::string thread_name = "kit_ws_" + _sessionId; +static const std::string thread_name = "kit_ws_" + _session->getId(); #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 + "."); @@ -373,23 +365,6 @@ public: try { -// Open websocket connection between the child process and the -// parent. The parent forwards us requests that it can't handle. - -HTTPClientSession cs("127.0.0.1", MASTER_PORT_NUMBER); -cs.setTimeout(0); -HTTPRequest request(HTTPRequest::HTTP_GET, CHILD_URI + _sessionId); -HTTPResponse response; -_ws = std::make_shared(cs, request, response); - -_session.reset(new ChildProcessSession(_sessionId, _ws, _loKit, _loKitDocument, _jailId, _onLoad, _onUnload)); -_ws->setReceiveTimeout(0); - -// child Jail TID PID -std::string hello("child " + _jailId + " " + - _sessionId + " " + std::to_string(Process::id())); -_session->sendTextFrame(hello); - TileQueue queue; QueueHandler handler(queue, _session, "kit_queue_" + _session->getId()); @@ -405,9 +380,12 @@ public: if (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE) { -std::string firstLine = getFirstLine(buffer, n); +const std::string firstLine = getFirstLine(buffer, n); if (firstLine == "eof") +{ +Log::info("Recieved EOF. Finishing."); break; +} StringTokenizer tokens(firstLine, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM); @@ -446,16 +424,10 @@ public: } private: -LibreOfficeKit *_loKit; -LibreOfficeKitDocument *_loKitDocument; -const std::string _jailId; -const std::string _sessionId; Thread _thread; std::shared_ptr _session; -volatile bool _stop; -std::function _onLoad; -std::function _onUnload; std::shared_ptr _ws; +volatile bool _stop; }; // A document container. @@ -554,10 +526,26 @@ public: << " view for url: " << _url << "for thread: " << sessionId << " on child: " << _jailId << Log::end; -auto thread = std::make_shared(_loKit, _loKitDocument, _jailId, sessionId, - [this](const std::string& id, const std::string& uri) { return onLoad(id, uri); }, - [this](const std::string& id) { onUnload(id); }); +// Open websocket connection between the child process and the +// parent. The parent forwards us requests that it can't handle. + +HTTPClientSession cs("127.0.0.1", M
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp loolwsd/LOOLWSD.cpp
loolwsd/LOOLKit.cpp |4 ++-- loolwsd/LOOLWSD.cpp | 26 +- 2 files changed, 15 insertions(+), 15 deletions(-) New commits: commit f577e48f18c01616269159c839b25beda9a4355f Author: Ashod Nakashian Date: Sun Jan 10 10:35:28 2016 -0500 loolwsd: child Session ID in URI Change-Id: Ide04425fe29d17dd2db1aea532de421b8f0e3669 Reviewed-on: https://gerrit.libreoffice.org/21329 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 7e2f8ad..4750d08 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -362,7 +362,7 @@ public: void run() override { -static const std::string thread_name = "kit_socket_" + _sessionId; +static const std::string thread_name = "kit_ws_" + _sessionId; #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 + "."); @@ -376,7 +376,7 @@ public: HTTPClientSession cs("127.0.0.1", MASTER_PORT_NUMBER); cs.setTimeout(0); -HTTPRequest request(HTTPRequest::HTTP_GET, CHILD_URI); +HTTPRequest request(HTTPRequest::HTTP_GET, CHILD_URI + _sessionId); HTTPResponse response; _ws = std::make_shared(cs, request, response); diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index 71e9915..51bd75c 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -308,7 +308,8 @@ public: void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response) override { -const std::string thread_name = "client_socket"; +const auto id = LOOLWSD::GenSessionId(); +const std::string thread_name = "client_ws_" + id; #ifdef __linux if (prctl(PR_SET_NAME, reinterpret_cast(thread_name.c_str()), 0, 0, 0) != 0) @@ -333,7 +334,6 @@ public: // Load the document. std::shared_ptr ws; const LOOLSession::Kind kind = LOOLSession::Kind::ToClient; -const auto id = LOOLWSD::GenSessionId(); auto session = std::make_shared(id, kind, ws); const std::string filePrefix("file://"); const std::string load = "load url=" + filePrefix + fromPath; @@ -430,8 +430,6 @@ public: try { auto ws = std::make_shared(request, response); - -const std::string id = LOOLWSD::GenSessionId(); auto session = std::make_shared(id, LOOLSession::Kind::ToClient, ws); // For ToClient sessions, we store incoming messages in a queue and have a separate @@ -493,21 +491,23 @@ public: void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response) override { assert(request.serverAddress().port() == MASTER_PORT_NUMBER); -assert(request.getURI() == LOOLWSD::CHILD_URI); +assert(request.getURI().find(LOOLWSD::CHILD_URI) == 0); -const std::string thread_name = "prison_socket"; +std::string thread_name = "prison_ws_"; +try +{ +const auto index = request.getURI().find_last_of('/'); +const auto id = request.getURI().substr(index + 1); + +thread_name += id; #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 + "."); +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."); +Log::debug("Thread [" + thread_name + "] started."); -try -{ auto ws = std::make_shared(request, response); - -const std::string id; auto session = std::make_shared(id, LOOLSession::Kind::ToPrisoner, ws); SocketProcessor(ws, response, [&session](const char* data, const int size, bool) ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 15 +++ 1 file changed, 11 insertions(+), 4 deletions(-) New commits: commit c83f3937d4faeac4eda2a03a9eac3244429ef46b Author: Ashod Nakashian Date: Sun Jan 10 10:34:47 2016 -0500 loolwsd: Document locks and view counters Change-Id: I2bae3fd7136e5bb85276f5cad246497e51fbfdd0 Reviewed-on: https://gerrit.libreoffice.org/21328 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 35fc483..7e2f8ad 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -485,6 +485,8 @@ public: ~Document() { +std::unique_lock lock(_mutex); + Log::info("~Document dtor for url [" + _url + "] on child [" + _jailId + "]. There are " + std::to_string(_clientViews) + " views."); @@ -597,6 +599,8 @@ private: Document* self = reinterpret_cast(pData); if (self) { +std::unique_lock lock(self->_mutex); + for (auto& it: self->_connections) { if (it.second->isRunning()) @@ -615,6 +619,10 @@ private: /// Load a document (or view) and register callbacks. LibreOfficeKitDocument* onLoad(const std::string& sessionId, const std::string& uri) { +std::unique_lock lock(_mutex); + +Log::info("Session " + sessionId + " is unloading. " + std::to_string(_clientViews) + " views loaded."); + const unsigned intSessionId = Util::decodeId(sessionId); const auto it = _connections.find(intSessionId); if (it == _connections.end() || !it->second) @@ -644,16 +652,16 @@ private: _loKitDocument->pClass->registerCallback(_loKitDocument, ViewCallback, reinterpret_cast(intSessionId)); -++_clientViews; Log::info() << "Document [" << _url << "] view [" << viewId << "] loaded, leaving " -<< _clientViews << " views." << Log::end; +<< (_clientViews + 1) << " views." << Log::end; } else { _loKitDocument->pClass->registerCallback(_loKitDocument, DocumentCallback, this); } +++_clientViews; return _loKitDocument; } @@ -675,8 +683,7 @@ private: if (_multiView && _loKitDocument) { ---_clientViews; -Log::info() << "Document [" << _url << "] view [" +Log::info() << "Document [" << _url << "] session [" << sessionId << "] unloaded, leaving " << _clientViews << " views." << Log::end; ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 54 1 file changed, 21 insertions(+), 33 deletions(-) New commits: commit d20e9399fc194143d71383d4bfefb5f3eef2a947 Author: Henry Castro Date: Sat Jan 9 07:27:57 2016 -0400 loolwsd: revert, refactor lokit Document I did not consider shared document case. diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 32c8f4d..ff7c3c3 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -470,13 +470,14 @@ private: class Document { public: -Document(LibreOfficeKit *loKit, const std::string& jailId) +Document(LibreOfficeKit *loKit, const std::string& jailId, + const std::string& url) : _loKit(loKit), _jailId(jailId), -_url(""), +_url(url), _loKitDocument(nullptr) { -Log::info("Document ctor on child [" + jailId + "]."); +Log::info("Document ctor for url [" + url + "] on child [" + jailId + "]."); } ~Document() @@ -505,10 +506,9 @@ public: } } -void createSession(const std::string& sessionId, const std::string& url) +void createSession(const std::string& sessionId) { const auto& aItem = _connections.find(sessionId); -_url = url; if (aItem != _connections.end()) { @@ -579,19 +579,13 @@ public: return _connections.size() > 0; } -const std::string& getURL() -{ -return _url; -} - private: void onLoad(LibreOfficeKitDocument *loKitDocument, const int viewId) { Log::info("Document [" + _url + "] loaded as view #" + std::to_string(viewId) + "."); -// TODO. destroy lokit document when changed URL -// if (_loKitDocument != nullptr) -//assert(_loKitDocument == loKitDocument); +if (_loKitDocument != nullptr) +assert(_loKitDocument == loKitDocument); _loKitDocument = loKitDocument; } @@ -604,7 +598,7 @@ private: LibreOfficeKit *_loKit; const std::string _jailId; -std::string _url; +const std::string _url; LibreOfficeKitDocument *_loKitDocument; @@ -627,6 +621,8 @@ void lokit_main(const std::string &loSubPath, const std::string& jailId, const s assert(!jailId.empty()); assert(!loSubPath.empty()); +std::map> _documents; + static const std::string process_name = "loolkit"; #ifdef __linux if (prctl(PR_SET_NAME, reinterpret_cast(process_name.c_str()), 0, 0, 0) != 0) @@ -650,9 +646,6 @@ void lokit_main(const std::string &loSubPath, const std::string& jailId, const s exit(-1); } -// Singlenton instance -std::shared_ptr pDocument(std::make_shared(loKit.get(), jailId)); - try { int writerBroker; @@ -729,16 +722,14 @@ void lokit_main(const std::string &loSubPath, const std::string& jailId, const s if (tokens[0] == "search") { -// remove unloaded documents -pDocument->purgeSessions(); - -if (!pDocument->hasConnections()) +if (_documents.empty()) { aResponse += "empty \r\n"; } else { -aResponse += (pDocument->getURL() == tokens[1] ? "ok \r\n" : "no \r\n"); +const auto& it = _documents.find(tokens[1]); +aResponse += (it != _documents.end() ? "ok \r\n" : "no \r\n"); } } else if (tokens[0] == "thread") @@ -746,16 +737,13 @@ void lokit_main(const std::string &loSubPath, const std::string& jailId, const s const std::string& sessionId = tokens[1]; const std::string& url = tokens[2]; -if (!pDocument->hasConnections() || pDocument->getURL() == url) -{ -Log::debug("Thread request for session [" + sessionId + "], url: [" + url + "]."); -pDocument->createSession(sessionId, url); -aResponse += "ok \r\n"; -} -else -{ -aResponse += "no \r\n"; -} +Log::debug("Thread request for session [" + sessionId + "], url: [" + url + "]."); +auto it = _documents.lower_bound(url); +if (it == _documents.end()) +it = _documents.emplace_hint(it, url, std::make_shared(loKit.get(), jailId, url)); + +it->second->createSession(sessionId); +aResponse += "ok \r\n"; } else
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 57 ++-- 1 file changed, 25 insertions(+), 32 deletions(-) New commits: commit 82b3b25d0aca6174690c76d971834608bf25907d Author: Henry Castro Date: Fri Jan 8 10:37:48 2016 -0400 loolwsd: refactor lokit Document + Every lokit process acquire an unique URL document to open it + Every lokit process acquired with an URL document could open multiple view of the same URL document + Every lokit process acquire a new unique URL document if and only if no exists opened documents. + if a lokit process dies is an abnormal state, and it should take actions to recovery session document. + An initial lokit process with no acquire URL document is in waiting state. diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 2029c7c..c46c260 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -470,14 +470,13 @@ private: class Document { public: -Document(LibreOfficeKit *loKit, const std::string& jailId, - const std::string& url) +Document(LibreOfficeKit *loKit, const std::string& jailId) : _loKit(loKit), _jailId(jailId), -_url(url), +_url(""), _loKitDocument(nullptr) { -Log::info("Document ctor for url [" + url + "] on child [" + jailId + "]."); +Log::info("Document ctor on child [" + jailId + "]."); } ~Document() @@ -506,9 +505,11 @@ public: } } -void createSession(const std::string& sessionId) +void createSession(const std::string& sessionId, const std::string& url) { const auto& aItem = _connections.find(sessionId); +_url = url; + if (aItem != _connections.end()) { // found item, check if still running @@ -578,13 +579,19 @@ public: return _connections.size() > 0; } +const std::string& getURL() +{ +return _url; +} + private: void onLoad(LibreOfficeKitDocument *loKitDocument, const int viewId) { Log::info("Document [" + _url + "] loaded as view #" + std::to_string(viewId) + "."); -if (_loKitDocument != nullptr) -assert(_loKitDocument == loKitDocument); +// TODO. destroy lokit document when changed URL +// if (_loKitDocument != nullptr) +//assert(_loKitDocument == loKitDocument); _loKitDocument = loKitDocument; } @@ -597,7 +604,7 @@ private: LibreOfficeKit *_loKit; const std::string _jailId; -const std::string _url; +std::string _url; LibreOfficeKitDocument *_loKitDocument; @@ -617,8 +624,6 @@ void lokit_main(const std::string &loSubPath, const std::string& jailId, const s char* pStart = nullptr; char* pEnd = nullptr; -std::map> _documents; - assert(!jailId.empty()); assert(!loSubPath.empty()); @@ -645,6 +650,9 @@ void lokit_main(const std::string &loSubPath, const std::string& jailId, const s exit(-1); } +// Singlenton instance +std::shared_ptr pDocument(std::make_shared(loKit.get(), jailId)); + try { int writerBroker; @@ -721,27 +729,16 @@ void lokit_main(const std::string &loSubPath, const std::string& jailId, const s if (tokens[0] == "search") { -// remove document that is unloaded -for (auto it =_documents.cbegin(); it != _documents.cend(); ) -{ -it->second->purgeSessions(); -if (!it->second->hasConnections()) -{ -_documents.erase(it++); -continue; -} -it++; -} +// remove unloaded documents +pDocument->purgeSessions(); -if (_documents.empty()) +if (!pDocument->hasConnections()) { aResponse += "empty \r\n"; } else { -const auto& it = _documents.begin(); -aResponse += (it != _documents.end() ? "ok \r\n" : "no \r\n"); -// TODO. it exists just one instance Document +aResponse += ( pDocument->getURL() == tokens[1] ? "ok \r\n" : "no \r\n"); } } else if (tokens[0] == "thread") @@ -749,14 +746,10 @@ void lokit_main(const std::string &loSubPath, const std::string& jailId, const s const std::string& sessionId = tokens[1]; const std::string& url = tokens[2]; -auto it = _documents.lower_bound(url); -
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp |3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) New commits: commit ab1a3a147ead52683451b797776df72181ba8ad4 Author: Henry Castro Date: Thu Jan 7 23:43:09 2016 -0400 loolwsd: not necessary to find session Every lokit instances has a unique URL, that could contain multiple views. diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 8ac56d3..2029c7c 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -739,8 +739,9 @@ void lokit_main(const std::string &loSubPath, const std::string& jailId, const s } else { -const auto& it = _documents.find(tokens[1]); +const auto& it = _documents.begin(); aResponse += (it != _documents.end() ? "ok \r\n" : "no \r\n"); +// TODO. it exists just one instance Document } } else if (tokens[0] == "thread") ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp
loolwsd/LOOLKit.cpp | 30 ++ 1 file changed, 30 insertions(+) New commits: commit 2c7b4490ec7f877f891096a6ad108e5b87364adf Author: Henry Castro Date: Thu Jan 7 23:23:41 2016 -0400 loolwsd: ensure to remove the connection of unloaded document diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index ba7ab62..8ac56d3 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -560,6 +560,24 @@ public: } } +void purgeSessions() +{ +for (auto it =_connections.cbegin(); it != _connections.cend(); ) +{ +if (!it->second->isRunning()) +{ +_connections.erase(it++); +continue; +} +it++; +} +} + +bool hasConnections() +{ +return _connections.size() > 0; +} + private: void onLoad(LibreOfficeKitDocument *loKitDocument, const int viewId) @@ -703,6 +721,18 @@ void lokit_main(const std::string &loSubPath, const std::string& jailId, const s if (tokens[0] == "search") { +// remove document that is unloaded +for (auto it =_documents.cbegin(); it != _documents.cend(); ) +{ +it->second->purgeSessions(); +if (!it->second->hasConnections()) +{ +_documents.erase(it++); +continue; +} +it++; +} + if (_documents.empty()) { aResponse += "empty \r\n"; ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLKit.cpp loolwsd/LOOLWSD.cpp loolwsd/QueueHandler.hpp
loolwsd/LOOLKit.cpp |6 +- loolwsd/LOOLWSD.cpp | 31 ++- loolwsd/QueueHandler.hpp |2 -- 3 files changed, 31 insertions(+), 8 deletions(-) New commits: commit 7bf3fe843a62061deff2f6c2f269c6713e4861f6 Author: Ashod Nakashian Date: Wed Jan 6 09:13:21 2016 -0500 loolwsd: more exception handling Change-Id: I7ac694395e2c231565bd84a7cd7813498dba387f Reviewed-on: https://gerrit.libreoffice.org/21163 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index d468739..6c765ab 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -432,7 +432,7 @@ public: } catch (const Exception& exc) { -Log::error() << exc.displayText() +Log::error() << "Error: " << exc.displayText() << (exc.nested() ? " (" + exc.nested()->displayText() + ")" : "") << Log::end; } @@ -440,6 +440,10 @@ public: { Log::error(std::string("Exception: ") + exc.what()); } +catch (...) +{ +Log::error("Unexpected Exception."); +} Log::debug("Thread [" + thread_name + "] finished."); } diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index 979bbb4..2669011 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -445,7 +445,8 @@ public: // FIXME: There is a race here when a request A gets in the queue and // is processed _after_ a later request B, because B gets processed // synchronously and A is waiting in the queue thread. -// Fix is to push everything into the queue. +// The fix is to push everything into the queue +// (i.e. change MessageQueue to vector). if (singleLine) { const std::string firstLine = getFirstLine(data, size); @@ -462,9 +463,19 @@ public: queue.put("eof"); queueHandlerThread.join(); } -catch (const IOException& exc) +catch (const Exception& exc) { -Log::error("IOException: " + exc.message()); +Log::error() << "Error: " << exc.displayText() + << (exc.nested() ? " (" + exc.nested()->displayText() + ")" : "") + << Log::end; +} +catch (const std::exception& exc) +{ +Log::error(std::string("Exception: ") + exc.what()); +} +catch (...) +{ +Log::error("Unexpected Exception."); } Log::debug("Thread [" + thread_name + "] finished."); @@ -501,9 +512,19 @@ public: return session->handleInput(data, size); }); } -catch (const IOException& exc) +catch (const Exception& exc) +{ +Log::error() << "Error: " << exc.displayText() + << (exc.nested() ? " (" + exc.nested()->displayText() + ")" : "") + << Log::end; +} +catch (const std::exception& exc) +{ +Log::error(std::string("Exception: ") + exc.what()); +} +catch (...) { -Log::error("IOException: " + exc.message()); +Log::error("Unexpected Exception."); } Log::debug("Thread [" + thread_name + "] finished."); diff --git a/loolwsd/QueueHandler.hpp b/loolwsd/QueueHandler.hpp index 5111382..759c175 100644 --- a/loolwsd/QueueHandler.hpp +++ b/loolwsd/QueueHandler.hpp @@ -48,12 +48,10 @@ public: catch (const std::exception& exc) { Log::error(std::string("Exception: ") + exc.what()); -raise(SIGABRT); } catch (...) { Log::error("Unexpected Exception."); -raise(SIGABRT); } Log::debug("Thread [" + _name + "] finished."); ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits