[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/LOOLWSD.cpp wsd/LOOLWSD.hpp

2020-05-02 Thread Michael Meeks (via logerrit)
 wsd/DocumentBroker.cpp |2 +-
 wsd/LOOLWSD.cpp|7 ++-
 wsd/LOOLWSD.hpp|8 ++--
 3 files changed, 5 insertions(+), 12 deletions(-)

New commits:
commit fdd4b4f63ddd16679a5a7035aa14d6e02fd57fdd
Author: Michael Meeks 
AuthorDate: Sat May 2 19:14:05 2020 +0100
Commit: Michael Meeks 
CommitDate: Sat May 2 21:31:25 2020 +0200

mobile: remove a few conditionals.

Change-Id: I5f306904b0b0533290d5533bbc3452217689eaec
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/93324
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Michael Meeks 

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index b6defa9d5..801343c63 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -228,7 +228,7 @@ void DocumentBroker::pollThread()
 do
 {
 static const int timeoutMs = COMMAND_TIMEOUT_MS * 5;
-_childProcess = getNewChild_Blocks();
+_childProcess = getNewChild_Blocks(getPublicUri().getPath());
 if (_childProcess ||
 
std::chrono::duration_cast(std::chrono::steady_clock::now()
 -
   
_threadStart).count() > timeoutMs)
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index f4812ff30..dbe119067 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -491,17 +491,14 @@ static size_t addNewChild(const 
std::shared_ptr& child)
 std::mutex LOOLWSD::lokit_main_mutex;
 #endif
 
-std::shared_ptr getNewChild_Blocks(
-#if MOBILEAPP
- const std::string& uri
-#endif
- )
+std::shared_ptr getNewChild_Blocks(const std::string& uri)
 {
 std::unique_lock lock(NewChildrenMutex);
 
 const auto startTime = std::chrono::steady_clock::now();
 
 #if !MOBILEAPP
+(void)uri;
 LOG_DBG("getNewChild: Rebalancing children.");
 int numPreSpawn = LOOLWSD::NumPreSpawnedChildren;
 ++numPreSpawn; // Replace the one we'll dispatch just now.
diff --git a/wsd/LOOLWSD.hpp b/wsd/LOOLWSD.hpp
index f2f7e0abc..dc0a68e06 100644
--- a/wsd/LOOLWSD.hpp
+++ b/wsd/LOOLWSD.hpp
@@ -32,15 +32,11 @@ class TraceFileWriter;
 class DocumentBroker;
 class ClipboardCache;
 
-std::shared_ptr getNewChild_Blocks(
-#if MOBILEAPP
- const std::string& uri
-#endif
- );
+std::shared_ptr getNewChild_Blocks(const std::string& uri);
+
 // A WSProcess object in the WSD process represents a descendant process, 
either the direct child
 // process FORKIT or a grandchild KIT process, with which the WSD process 
communicates through a
 // WebSocket.
-
 class WSProcess
 {
 public:
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/LOOLWSD.cpp wsd/LOOLWSD.hpp

2020-04-16 Thread Ashod Nakashian (via logerrit)
 wsd/DocumentBroker.cpp |8 
 wsd/LOOLWSD.cpp|3 ++-
 wsd/LOOLWSD.hpp|4 ++--
 3 files changed, 8 insertions(+), 7 deletions(-)

New commits:
commit 40684c46872899f9ef705f267b8597007f3703d1
Author: Ashod Nakashian 
AuthorDate: Fri Apr 10 09:37:29 2020 -0400
Commit: Ashod Nakashian 
CommitDate: Fri Apr 17 02:35:52 2020 +0200

wsd: const correctness and cosmetics

Change-Id: I46751dc0a6d7c693fd9ab371c1e9a12bac309611
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/92098
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Ashod Nakashian 

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index bbe3b7937..8c342c4c3 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -75,7 +75,7 @@ void sendLastModificationTime(const std::shared_ptr& 
session,
 
 std::stringstream stream;
 stream << "lastmodtime: " << documentLastModifiedTime;
-std::string message = stream.str();
+const std::string message = stream.str();
 session->sendTextFrame(message);
 if (documentBroker)
 documentBroker->broadcastMessage(message);
@@ -982,7 +982,7 @@ bool DocumentBroker::saveToStorageInternal(const 
std::string& sessionId, bool su
 if (!isSaveAs && newFileModifiedTime == _lastFileModifiedTime && !isRename)
 {
 // Nothing to do.
-auto timeInSec = std::chrono::duration_cast
+const auto timeInSec = std::chrono::duration_cast
 (std::chrono::system_clock::now() 
- _lastFileModifiedTime);
 LOG_DBG("Skipping unnecessary saving to URI [" << uriAnonym << "] with 
docKey [" << _docKey <<
 "]. File last modified " << timeInSec.count() << " seconds 
ago.");
@@ -1140,7 +1140,7 @@ void DocumentBroker::refreshLock()
 {
 assertCorrectThread();
 
-std::string savingSessionId = getWriteableSessionId();
+const std::string savingSessionId = getWriteableSessionId();
 LOG_TRC("Refresh lock " << _lockCtx->_lockToken << " with session " << 
savingSessionId);
 
 auto it = _sessions.find(savingSessionId);
@@ -1171,7 +1171,7 @@ bool DocumentBroker::autoSave(const bool force, const 
bool dontSaveIfUnmodified)
 LOG_TRC("Checking to autosave [" << _docKey << "].");
 
 // Which session to use when auto saving ?
-std::string savingSessionId = getWriteableSessionId();
+const std::string savingSessionId = getWriteableSessionId();
 
 bool sent = false;
 if (force)
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index e40ec7a47..0796b53dd 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -1755,7 +1755,7 @@ bool LOOLWSD::createForKit()
 // Below line will be executed by PrisonerPoll thread.
 ForKitProc = nullptr;
 PrisonerPoll.setForKitProcess(ForKitProc);
-
+
 // ForKit always spawns one.
 ++OutstandingForks;
 
@@ -3691,6 +3691,7 @@ int LOOLWSD::innerMain()
 LOG_INF("Removing jail [" << path << "].");
 FileUtil::removeFile(path, true);
 }
+
 if (UnitBase::isUnitTesting())
 {
 LOG_TRC("Removing sub-childroot: of " + ChildRoot);
diff --git a/wsd/LOOLWSD.hpp b/wsd/LOOLWSD.hpp
index 4470e8871..821a7e5e4 100644
--- a/wsd/LOOLWSD.hpp
+++ b/wsd/LOOLWSD.hpp
@@ -48,7 +48,7 @@ class WSProcess
 public:
 /// @param pid is the process ID.
 /// @param socket is the underlying Sockeet to the process.
-WSProcess(const std::string& name, 
+WSProcess(const std::string& name,
   const Poco::Process::PID pid,
   const std::shared_ptr& socket,
   std::shared_ptr handler) :
@@ -369,7 +369,7 @@ public:
 /// Close document with @docKey and a @message
 static void closeDocument(const std::string& docKey, const std::string& 
message);
 
-/// Autosave a given document
+/// Autosave a given document (currently only called from Admin).
 static void autoSave(const std::string& docKey);
 
 /// Anonymize the basename of filenames, preserving the path and extension.
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/LOOLWSD.cpp

2019-11-28 Thread Michael Meeks (via logerrit)
 wsd/DocumentBroker.cpp |6 ++
 wsd/LOOLWSD.cpp|3 +--
 2 files changed, 7 insertions(+), 2 deletions(-)

New commits:
commit 039ca3540e84498e24da33cdea51c70163aafca8
Author: Michael Meeks 
AuthorDate: Thu Nov 28 18:05:04 2019 +
Commit: Michael Meeks 
CommitDate: Thu Nov 28 18:05:04 2019 +

tdf#125755: specialize reduced decoding for mobile apps.

The WOPI multiple encoding magic is unpleasant; best not to try to
unwind it all now.

This fixes Download-As and SllideShow pieces.

cf. c806acb157fa501a8be872042b534a2f49641e62

Change-Id: Ie06ad386c7a30e0f572e299e50fc949ce41b09f5

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index ddfaa922d..177da0618 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -86,7 +86,13 @@ void sendLastModificationTime(const 
std::shared_ptr& session,
 Poco::URI DocumentBroker::sanitizeURI(const std::string& uri)
 {
 // The URI of the document should be url-encoded.
+#if !MOBILEAPP
+std::string decodedUri;
+Poco::URI::decode(uri, decodedUri);
+Poco::URI uriPublic(decodedUri);
+#else
 Poco::URI uriPublic(uri);
+#endif
 
 if (uriPublic.isRelative() || uriPublic.getScheme() == "file")
 {
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 221d179ef..f76aaabc1 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -2430,8 +2430,7 @@ private:
 }
 LOG_TRC("Clipboard request for us: " << serverId << " with tag " << 
tag);
 
-const auto uriPublic = DocumentBroker::sanitizeURI(WOPISrc);
-const auto docKey = DocumentBroker::getDocKey(uriPublic);
+const auto docKey = 
DocumentBroker::getDocKey(DocumentBroker::sanitizeURI(WOPISrc));
 
 std::shared_ptr docBroker;
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/LOOLWSD.cpp

2019-11-04 Thread Ashod Nakashian (via logerrit)
 wsd/DocumentBroker.cpp |2 -
 wsd/LOOLWSD.cpp|   64 +++--
 2 files changed, 42 insertions(+), 24 deletions(-)

New commits:
commit f18cd4c45855c84659af59afad8b936f5c087a0e
Author: Ashod Nakashian 
AuthorDate: Sun Nov 3 15:03:11 2019 -0500
Commit: Andras Timar 
CommitDate: Mon Nov 4 09:36:24 2019 +0100

wsd: improved shutdown cleanup

(cherry picked from commit 5eb58d4e13ed43156115d25482dffa96d7768bfe)

Change-Id: Ibdb822575c376af6065080070bf6b89c240ce67b
Reviewed-on: https://gerrit.libreoffice.org/81977
Reviewed-by: Andras Timar 
Tested-by: Andras Timar 

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index d3b0c654f..754844e89 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -485,7 +485,7 @@ void DocumentBroker::joinThread()
 
 void DocumentBroker::stop(const std::string& reason)
 {
-LOG_DBG("Closing DocumentBroker for docKey [" << _docKey << "] with 
reason: " << reason);
+LOG_DBG("Stopping DocumentBroker for docKey [" << _docKey << "] with 
reason: " << reason);
 _closeReason = reason; // used later in the polling loop
 _stop = true;
 _poll->wakeup();
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index f6d5132dc..0a66ac719 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -3488,8 +3488,8 @@ int LOOLWSD::innerMain()
 #if ENABLE_DEBUG
 if (careerSpanMs > 0 && timeSinceStartMs > careerSpanMs)
 {
-LOG_INF(timeSinceStartMs << " milliseconds gone, finishing as 
requested.");
-break;
+LOG_INF(timeSinceStartMs << " milliseconds gone, finishing as 
requested. Setting ShutdownRequestFlag.");
+SigUtil::requestShutdown();
 }
 #endif
 }
@@ -3502,36 +3502,54 @@ int LOOLWSD::innerMain()
 srv.stop();
 
 // atexit handlers tend to free Admin before Documents
-LOG_INF("Cleaning up lingering documents.");
-if (SigUtil::getShutdownRequestFlag() || SigUtil::getTerminationFlag())
+LOG_INF("Exiting. Cleaning up lingering documents.");
+if (!SigUtil::getShutdownRequestFlag())
 {
-// Don't stop the DocBroker, they will exit.
-const size_t sleepMs = 300;
-const size_t count = std::max(COMMAND_TIMEOUT_MS, 2000) / 
sleepMs;
-for (size_t i = 0; i < count; ++i)
-{
-std::unique_lock docBrokersLock(DocBrokersMutex);
-cleanupDocBrokers();
-if (DocBrokers.empty())
-break;
-docBrokersLock.unlock();
-
-// Give them time to save and cleanup.
-std::this_thread::sleep_for(std::chrono::milliseconds(sleepMs));
-}
+// This shouldn't happen, but it's fail safe to always cleanup 
properly.
+LOG_WRN("Exiting WSD without ShutdownRequestFlag. Setting it now.");
+SigUtil::requestShutdown();
 }
-else
+
+// Don't stop the DocBroker, they will exit.
+constexpr size_t sleepMs = 500;
+constexpr size_t count = (COMMAND_TIMEOUT_MS * 4) / sleepMs;
+for (size_t i = 0; i < count; ++i)
 {
-// Stop and join.
-for (auto& docBrokerIt : DocBrokers)
-docBrokerIt.second->joinThread();
+std::unique_lock docBrokersLock(DocBrokersMutex);
+if (DocBrokers.empty())
+break;
+
+LOG_DBG("Waiting for " << DocBrokers.size() << " documents to stop.");
+cleanupDocBrokers();
+docBrokersLock.unlock();
+
+// Give them time to save and cleanup.
+std::this_thread::sleep_for(std::chrono::milliseconds(sleepMs));
 }
 
 // Disable thread checking - we'll now cleanup lots of things if we can
 Socket::InhibitThreadChecks = true;
 SocketPoll::InhibitThreadChecks = true;
 
-DocBrokers.clear();
+// Wait for the DocumentBrokers. They must be saving/uploading now.
+// Do not stop them! Otherwise they might not save/upload the document.
+// We block until they finish, or the service stopping times out.
+{
+std::unique_lock docBrokersLock(DocBrokersMutex);
+for (auto& docBrokerIt : DocBrokers)
+{
+std::shared_ptr docBroker = docBrokerIt.second;
+if (docBroker && docBroker->isAlive())
+{
+LOG_DBG("Joining docBroker [" << docBrokerIt.first << "].");
+docBroker->joinThread();
+}
+}
+
+// Now should be safe to destroy what's left.
+cleanupDocBrokers();
+DocBrokers.clear();
+}
 
 #if !defined(KIT_IN_PROCESS) && !MOBILEAPP
 // Terminate child processes
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/LOOLWSD.cpp wsd/LOOLWSD.hpp wsd/Storage.hpp

2017-06-06 Thread Ashod Nakashian
 wsd/DocumentBroker.cpp |3 ++-
 wsd/LOOLWSD.cpp|8 +++-
 wsd/LOOLWSD.hpp|7 +++
 wsd/Storage.hpp|4 +++-
 4 files changed, 19 insertions(+), 3 deletions(-)

New commits:
commit 194faa6d693416ece2e17da34871b109e5243a6f
Author: Ashod Nakashian 
Date:   Tue Jun 6 23:43:48 2017 -0400

wsd: force readonly for view file types per discovery.xml

File extensions marked as view (as opposed to edit)
in discovery.xml are now forced to be read-only,
regardless of what the client tries to request.

Change-Id: I3eb00c33ff716800dc317f7377281c6d5f0909d7
Reviewed-on: https://gerrit.libreoffice.org/38480
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index a80b9395..d2c44b63 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -431,7 +431,8 @@ bool DocumentBroker::load(const 
std::shared_ptr& session, const s
 username = wopifileinfo->_username;
 userExtraInfo = wopifileinfo->_userExtraInfo;
 
-if (!wopifileinfo->_userCanWrite)
+if (!wopifileinfo->_userCanWrite ||
+LOOLWSD::IsViewFileExtension(wopiStorage->getFileExtension()))
 {
 LOG_DBG("Setting the session as readonly");
 session->setReadOnly();
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 445027e2..07d371c8 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -550,6 +550,7 @@ std::string LOOLWSD::LOKitVersion;
 std::string LOOLWSD::ConfigFile = LOOLWSD_CONFIGDIR "/loolwsd.xml";
 Util::RuntimeConstant LOOLWSD::SSLEnabled;
 Util::RuntimeConstant LOOLWSD::SSLTermination;
+std::set LOOLWSD::ViewFileExtensions;
 
 static std::string UnitTestLibrary;
 
@@ -2176,7 +2177,12 @@ private:
 
 for (unsigned long it = 0; it < listNodes->length(); ++it)
 {
-static_cast(listNodes->item(it))->setAttribute(urlsrc, 
uriValue);
+Element* elem = static_cast(listNodes->item(it));
+elem->setAttribute(urlsrc, uriValue);
+
+// Set the View extensions cache as well.
+if (elem->getAttribute("name") == "view")
+LOOLWSD::ViewFileExtensions.insert(elem->getAttribute("ext"));
 }
 
 std::ostringstream ostrXML;
diff --git a/wsd/LOOLWSD.hpp b/wsd/LOOLWSD.hpp
index 46538dc0..a608c6c1 100644
--- a/wsd/LOOLWSD.hpp
+++ b/wsd/LOOLWSD.hpp
@@ -55,6 +55,7 @@ public:
 static std::atomic NumConnections;
 static bool TileCachePersistent;
 static std::unique_ptr TraceDumper;
+static std::set ViewFileExtensions;
 
 /// Flag to shutdown the server.
 std::atomic ShutdownFlag;
@@ -81,6 +82,12 @@ public:
 return LOOLWSD::SSLTermination.get();
 }
 
+/// Return truee iff extension is marked as view action in discovery.xml.
+static bool IsViewFileExtension(const std::string& extension)
+{
+return ViewFileExtensions.find(extension) != ViewFileExtensions.end();
+}
+
 /// Returns the value of the specified application configuration,
 /// of the default, if one doesn't exist.
 template
diff --git a/wsd/Storage.hpp b/wsd/Storage.hpp
index 60c73275..09002bde 100644
--- a/wsd/Storage.hpp
+++ b/wsd/Storage.hpp
@@ -95,7 +95,9 @@ public:
 void forceSave() { _forceSave = true; }
 
 /// Returns the basic information about the file.
-FileInfo getFileInfo() { return _fileInfo; }
+const FileInfo& getFileInfo() const { return _fileInfo; }
+
+std::string getFileExtension() const { return 
Poco::Path(_fileInfo._filename).getExtension(); }
 
 /// Returns a local file path for the given URI.
 /// If necessary copies the file locally first.
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/LOOLWSD.cpp

2017-05-21 Thread Pranav Kant
 wsd/DocumentBroker.cpp |6 --
 wsd/LOOLWSD.cpp|   18 --
 2 files changed, 8 insertions(+), 16 deletions(-)

New commits:
commit 1ea87b627e077590c6eefa455ce3c8f7d0564068
Author: Pranav Kant 
Date:   Mon May 22 11:04:26 2017 +0530

wsd: Arrange exception handling a bit

Remove incorrect usage of std::uncaught_exception and handle
StorageConnectionException later.

Change-Id: I15ecd46b51e8ed33649fe876d46ce3d5fbae07cc

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 7d807acb..73178103 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -797,12 +797,6 @@ size_t DocumentBroker::addSession(const 
std::shared_ptr& session)
 throw std::runtime_error(msg);
 }
 }
-catch (const StorageConnectionException& exc)
-{
-// Alert user about failed load
-session->sendMessage("error: cmd=storage kind=loadfailed");
-throw;
-}
 catch (const StorageSpaceLowException&)
 {
 LOG_ERR("Out of storage while loading document with URI [" << 
session->getPublicUri().toString() << "].");
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index a2e868d9..3a877242 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -2129,18 +2129,16 @@ private:
 clientSession->sendMessage(msg);
 docBroker->stop();
 }
+catch (const StorageConnectionException& exc)
+{
+// Alert user about failed load
+const std::string msg = "error: cmd=storage 
kind=loadfailed";
+clientSession->sendMessage(msg);
+docBroker->stop();
+}
 catch (const std::exception& exc)
 {
-LOG_ERR("Error while handling loading : " << 
exc.what());
-// only send our default error message if we 
haven't handled the
-// exception already up the stack
-if (std::uncaught_exception())
-{
-// FIXME: Are we sure we want to say that 
all other failures due
-// to an 'unauthorized' WOPI host ?
-const std::string msg = "error: 
cmd=internal kind=unauthorized";
-clientSession->sendMessage(msg);
-}
+LOG_ERR("Error while loading : " << 
exc.what());
 docBroker->stop();
 }
 });
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/LOOLWSD.cpp wsd/LOOLWSD.hpp

2017-04-02 Thread Ashod Nakashian
 wsd/DocumentBroker.cpp |3 +++
 wsd/LOOLWSD.cpp|   16 
 wsd/LOOLWSD.hpp|4 +++-
 3 files changed, 14 insertions(+), 9 deletions(-)

New commits:
commit c81db872352443cb0c3ac0f7c0d68f27fcd34963
Author: Ashod Nakashian 
Date:   Sun Apr 2 19:56:42 2017 -0400

wsd: do child housekeeping on finishing DocBroker thread

Change-Id: I109737b79759986cb2a1cbfc6d711ee2f19ff59d
Reviewed-on: https://gerrit.libreoffice.org/36034
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index ae7f6e71..a89e3862 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -260,6 +260,9 @@ void DocumentBroker::pollThread()
 _poll->poll(std::min(flushTimeoutMs - elapsedMs, POLL_TIMEOUT_MS / 5));
 }
 
+// Cleanup.
+LOOLWSD::doHousekeeping();
+
 LOG_INF("Finished docBroker polling thread for docKey [" << _docKey << 
"].");
 }
 
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 2cc7bf51..6b2d633b 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -1101,6 +1101,11 @@ bool LOOLWSD::checkAndRestoreForKit()
 
 void PrisonerPoll::wakeupHook()
 {
+LOOLWSD::doHousekeeping();
+}
+
+void LOOLWSD::doHousekeeping()
+{
 if (!LOOLWSD::checkAndRestoreForKit())
 {
 // No children have died.
@@ -1136,11 +1141,6 @@ void PrisonerPoll::wakeupHook()
 cleanupDocBrokers();
 }
 
-void LOOLWSD::triggerChildAndDocHousekeeping()
-{
-PrisonerPoll.wakeup();
-}
-
 bool LOOLWSD::createForKit()
 {
 #ifdef KIT_IN_PROCESS
@@ -2428,9 +2428,9 @@ int LOOLWSD::innerMain()
 UnitWSD::get().invokeTest();
 
 // This timeout affects the recovery time of prespawned children.
-int msWait = UnitWSD::isUnitTesting() ?
-UnitWSD::get().getTimeoutMilliSeconds() / 4 :
-SocketPoll::DefaultPollTimeoutMs * 4;
+const int msWait = UnitWSD::isUnitTesting() ?
+   UnitWSD::get().getTimeoutMilliSeconds() / 4 :
+   SocketPoll::DefaultPollTimeoutMs * 4;
 mainWait.poll(msWait);
 
 // Wake the prisoner poll to spawn some children, if necessary.
diff --git a/wsd/LOOLWSD.hpp b/wsd/LOOLWSD.hpp
index b86b23ac..072a4a88 100644
--- a/wsd/LOOLWSD.hpp
+++ b/wsd/LOOLWSD.hpp
@@ -100,7 +100,9 @@ public:
 /// Return true when successfull.
 static bool createForKit();
 
-static void triggerChildAndDocHousekeeping();
+/// Checks forkit (and respawns), rebalances
+/// child kit processes and cleans up DocBrokers.
+static void doHousekeeping();
 
 protected:
 void initialize(Poco::Util::Application& self) override;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/LOOLWSD.cpp wsd/LOOLWSD.hpp

2017-03-27 Thread Ashod Nakashian
 wsd/DocumentBroker.cpp |3 +++
 wsd/LOOLWSD.cpp|   23 +--
 wsd/LOOLWSD.hpp|2 ++
 3 files changed, 18 insertions(+), 10 deletions(-)

New commits:
commit 1a6f6e9a65559756ead5c61804744e520ea749d3
Author: Ashod Nakashian 
Date:   Mon Mar 27 21:46:16 2017 -0400

wsd: trigger child and doc housekeeping upon terminating kit

Change-Id: I7ffbadb40221c19b24fd172d1b9aabcaa8c581e5
Reviewed-on: https://gerrit.libreoffice.org/35787
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 384e66cf..32f55aae 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -1304,6 +1304,9 @@ void 
DocumentBroker::terminateChild(std::unique_lock& lock, const st
 // Stop the polling thread.
 _poll->stop();
 _stop = true;
+
+// Trigger cleanup.
+LOOLWSD::triggerChildAndDocHousekeeping();
 }
 
 void DocumentBroker::closeDocument(const std::string& reason)
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 4e2c923a..f8d6aa03 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -1112,9 +1112,6 @@ bool LOOLWSD::checkAndRestoreForKit()
 
 void PrisonerPoll::wakeupHook()
 {
-/// FIXME: we should do this less frequently
-/// currently the prisoner poll wakes up quite
-/// a lot.
 if (!LOOLWSD::checkAndRestoreForKit())
 {
 // No children have died.
@@ -1144,6 +1141,18 @@ void PrisonerPoll::wakeupHook()
 #endif
 }
 }
+
+std::unique_lock docBrokersLock(DocBrokersMutex, 
std::defer_lock);
+if (docBrokersLock.try_lock())
+{
+cleanupDocBrokers();
+}
+}
+
+void LOOLWSD::triggerChildAndDocHousekeeping()
+{
+PrisonerPoll.wakeup();
+
 }
 
 bool LOOLWSD::createForKit()
@@ -2451,7 +2460,7 @@ int LOOLWSD::innerMain()
 UnitWSD::get().invokeTest();
 
 // This timeout affects the recovery time of prespawned children.
-mainWait.poll(SocketPoll::DefaultPollTimeoutMs);
+mainWait.poll(SocketPoll::DefaultPollTimeoutMs * 4);
 
 // Wake the prisoner poll to spawn some children, if necessary.
 PrisonerPoll.wakeup();
@@ -2462,12 +2471,6 @@ int LOOLWSD::innerMain()
 UnitWSD::get().getTimeoutMilliSeconds())
 UnitWSD::get().timeout();
 
-std::unique_lock docBrokersLock(DocBrokersMutex, 
std::defer_lock);
-if (docBrokersLock.try_lock())
-{
-cleanupDocBrokers();
-}
-
 #if ENABLE_DEBUG
 if (careerSpanSeconds > 0 && time(nullptr) > startTimeSpan + 
careerSpanSeconds)
 {
diff --git a/wsd/LOOLWSD.hpp b/wsd/LOOLWSD.hpp
index 2461a0d5..d20314c1 100644
--- a/wsd/LOOLWSD.hpp
+++ b/wsd/LOOLWSD.hpp
@@ -99,6 +99,8 @@ public:
 /// Return true when successfull.
 static bool createForKit();
 
+static void triggerChildAndDocHousekeeping();
+
 protected:
 void initialize(Poco::Util::Application& self) override;
 void defineOptions(Poco::Util::OptionSet& options) override;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/LOOLWSD.cpp

2017-03-12 Thread Ashod Nakashian
 wsd/DocumentBroker.cpp |3 ++
 wsd/LOOLWSD.cpp|   54 +
 2 files changed, 35 insertions(+), 22 deletions(-)

New commits:
commit 3d78e5f2a1a6c1369e6cdeddd39cb00a6e33d1bd
Author: Ashod Nakashian 
Date:   Sun Mar 12 22:31:50 2017 -0400

wsd: improved logging of extant DocBrokers after cleanup

Change-Id: I4de8fde607e9e94cbadd8e100d39e0e21f2f2bdc
Reviewed-on: https://gerrit.libreoffice.org/35126
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 25686bf..a53a7c1 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -1274,6 +1274,9 @@ void 
DocumentBroker::terminateChild(std::unique_lock& lock, const st
 
 _childProcess->close(false);
 }
+
+// Stop the polling thread.
+_poll->stop();
 }
 
 void DocumentBroker::closeDocument(const std::string& reason)
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 310d576..97cf845 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -261,38 +261,48 @@ bool cleanupDocBrokers()
 for (auto it = DocBrokers.begin(); it != DocBrokers.end(); )
 {
 auto docBroker = it->second;
+
+// If document busy at the moment, cleanup later.
 auto lock = docBroker->getDeferredLock();
-if (!lock.try_lock())
+if (lock.try_lock())
 {
-// Document busy at the moment, cleanup later.
-++it;
-continue;
-}
+// Remove idle documents after 1 hour.
+const bool idle = (docBroker->getIdleTimeSecs() >= 3600);
 
-// Remove idle documents after 1 hour.
-const bool idle = (docBroker->getIdleTimeSecs() >= 3600);
+// Cleanup used and dead entries.
+if ((docBroker->isLoaded() || docBroker->isMarkedToDestroy()) &&
+(docBroker->getSessionsCount() == 0 || !docBroker->isAlive() 
|| idle))
+{
+LOG_INF("Terminating " << (idle ? "idle" : "dead") <<
+" DocumentBroker for docKey [" << it->first << "].");
+docBroker->terminateChild(lock, idle ? "idle" : "");
 
-// Cleanup used and dead entries.
-if (docBroker->isLoaded() &&
-(docBroker->getSessionsCount() == 0 || !docBroker->isAlive() || 
idle))
-{
-LOG_INF("Removing " << (idle ? "idle" : "dead") <<
-" DocumentBroker for docKey [" << it->first << "].");
-it = DocBrokers.erase(it);
-docBroker->terminateChild(lock, idle ? "idle" : "");
-}
-else
-{
-++it;
+// Remove only when not alive.
+if (!docBroker->isAlive())
+{
+LOG_INF("Removing " << (idle ? "idle" : "dead") <<
+" DocumentBroker for docKey [" << it->first << 
"].");
+it = DocBrokers.erase(it);
+continue;
+}
+}
 }
+
+++it;
 }
 
 if (count != DocBrokers.size())
 {
-LOG_TRC("Have " << DocBrokers.size() << " DocBrokers after cleanup.");
-for (auto& pair : DocBrokers)
+auto logger = Log::trace();
+if (logger.enabled())
 {
-LOG_TRC("DocumentBroker [" << pair.first << "].");
+logger << "Have " << DocBrokers.size() << " DocBrokers after 
cleanup.\n";
+for (auto& pair : DocBrokers)
+{
+logger << "DocumentBroker [" << pair.first << "].\n";
+}
+
+LOG_END(logger);
 }
 
 return true;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/LOOLWSD.cpp

2017-02-10 Thread Miklos Vajna
 wsd/DocumentBroker.cpp |1 -
 wsd/LOOLWSD.cpp|2 ++
 2 files changed, 2 insertions(+), 1 deletion(-)

New commits:
commit f81ab32c57c71b123d137c0bd71dfc46a8f9ce48
Author: Miklos Vajna 
Date:   Fri Feb 10 09:07:30 2017 +0100

wsd: remove remaining unused using declarations

Change-Id: I7d0d453194bdd069654f29105e3f17769036cd39

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 32c4c17..0225f46 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -37,7 +37,6 @@
 using namespace LOOLProtocol;
 
 using Poco::JSON::Object;
-using Poco::StringTokenizer;
 
 void ChildProcess::socketProcessor()
 {
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 05cd665..97a6088 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -156,7 +156,9 @@ using Poco::ProcessHandle;
 using Poco::StreamCopier;
 using Poco::StringTokenizer;
 using Poco::TemporaryFile;
+#if FUZZER
 using Poco::Thread;
+#endif
 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: wsd/DocumentBroker.cpp wsd/LOOLWSD.cpp

2017-01-15 Thread Ashod Nakashian
 wsd/DocumentBroker.cpp |4 ++--
 wsd/LOOLWSD.cpp|2 ++
 2 files changed, 4 insertions(+), 2 deletions(-)

New commits:
commit 1c67d9387f026b0da814b4e3422bf42185cdcfa3
Author: Ashod Nakashian 
Date:   Tue Jan 10 17:10:10 2017 -0500

wsd: addSession now must be called under lock

Change-Id: I6148d7ac3edd88f922d258f39ea22b372dba84f0
Reviewed-on: https://gerrit.libreoffice.org/33124
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 4348e86..7d7bfee 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -594,11 +594,11 @@ std::string DocumentBroker::getJailRoot() const
 
 size_t DocumentBroker::addSession(std::shared_ptr& session)
 {
+Util::assertIsLocked(_mutex);
+
 const auto id = session->getId();
 const std::string aMessage = "session " + id + " " + _docKey;
 
-std::unique_lock lock(_mutex);
-
 try
 {
 // First load the document, since this can fail.
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index ca03df2..889b817 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -608,7 +608,9 @@ private:
 std::shared_ptr ws;
 auto session = std::make_shared(id, ws, 
docBroker, uriPublic);
 
+auto lock = docBroker->getLock();
 auto sessionsCount = docBroker->addSession(session);
+lock.unlock();
 LOG_TRC(docKey << ", ws_sessions++: " << sessionsCount);
 
 docBrokersLock.unlock();
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/LOOLWSD.cpp

2017-01-15 Thread Ashod Nakashian
 wsd/DocumentBroker.cpp |2 +
 wsd/LOOLWSD.cpp|   53 +++--
 2 files changed, 14 insertions(+), 41 deletions(-)

New commits:
commit 087f9930402c49d2f26bfab6ce1bb10012e33faa
Author: Ashod Nakashian 
Date:   Tue Jan 10 00:26:24 2017 -0500

wsd: use refactored createNewClientSession

Change-Id: I7d9128865eea6c5fd9f48b469fb35ede3c811b4b
Reviewed-on: https://gerrit.libreoffice.org/33123
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index cb20b14..4348e86 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -960,6 +960,8 @@ bool DocumentBroker::startDestroy(const std::string& id)
 
 // Last view going away, can destroy.
 _markToDestroy = (_sessions.size() <= 1);
+LOG_DBG("startDestroy on session [" << id << "] on docKey [" << _docKey <<
+"], markToDestroy: " << _markToDestroy << ", lastEditableSession: 
" << _lastEditableSession);
 return _lastEditableSession;
 }
 
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 5cc6b2c..ca03df2 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -833,8 +833,12 @@ private:
 auto docBroker = findOrCreateDocBroker(docKey, ws, id, uriPublic);
 if (docBroker)
 {
-// Process the request in an exception-safe way.
-processGetRequest(uri, ws, id, uriPublic, docBroker, 
isReadOnly);
+auto session = createNewClientSession(uri, ws, id, uriPublic, 
docBroker, isReadOnly);
+if (session)
+{
+// Process the request in an exception-safe way.
+processGetRequest(uri, ws, id, docBroker, session);
+}
 }
 }
 catch (const WebSocketErrorMessageException& exc)
@@ -1105,47 +1109,14 @@ private:
 }
 
 /// Process GET requests.
-static void processGetRequest(const std::string& uri, 
std::shared_ptr& ws, const std::string& id,
-  const Poco::URI& uriPublic, const 
std::shared_ptr& docBroker, const bool isReadOnly)
+static void processGetRequest(const std::string& uri,
+  std::shared_ptr& ws,
+  const std::string& id,
+  const std::shared_ptr& 
docBroker,
+  const std::shared_ptr& 
session)
 {
 LOG_CHECK_RET(docBroker && "Null docBroker instance", );
 const auto docKey = docBroker->getDocKey();
-
-std::shared_ptr session;
-try
-{
-// In case of WOPI, if this session is not set as readonly, it 
might be set so
-// later after making a call to WOPI host which tells us the 
permission on files
-// (UserCanWrite param).
-session = std::make_shared(id, ws, docBroker, 
uriPublic, isReadOnly);
-
-// Now we have a DocumentBroker and we're ready to process client 
commands.
-const std::string statusReady = "statusindicator: ready";
-LOG_TRC("Sending to Client [" << statusReady << "].");
-ws->sendFrame(statusReady.data(), statusReady.size());
-
-const std::string fs = 
FileUtil::checkDiskSpaceOnRegisteredFileSystems();
-if (!fs.empty())
-{
-LOG_WRN("File system of [" << fs << "] is dangerously low on 
disk space.");
-const std::string diskfullMsg = "error: cmd=internal 
kind=diskfull";
-// Alert the session currently being opened
-ws->sendFrame(diskfullMsg.data(), diskfullMsg.size());
-// Alert all other existing sessions also
-Util::alertAllUsers(diskfullMsg);
-}
-
-LOOLWSD::dumpEventTrace(docBroker->getJailId(), id, "NewSession: " 
+ uri);
-docBroker->addSession(session);
-}
-catch (const std::exception& exc)
-{
-LOG_WRN("Exception while preparing session [" << id << "].");
-removeDocBrokerSession(docBroker, id);
-
-return;
-}
-
 LOG_CHECK_RET(session && "Null ClientSession instance", );
 try
 {
@@ -1159,7 +1130,7 @@ private:
 []() { return TerminationFlag || SigUtil::isShuttingDown(); });
 
 // Connection terminated. Destroy session.
-LOG_DBG("Client session [" << id << "] terminated. Cleaning up.");
+LOG_DBG("Client session [" << id << "] on docKey [" << docKey << 
"] terminated. Cleaning up.");
 
 auto docLock = docBroker->getLock();
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/LOOLWSD.cpp

2017-01-02 Thread Ashod Nakashian
 wsd/DocumentBroker.cpp |   23 ---
 wsd/LOOLWSD.cpp|6 ++
 2 files changed, 18 insertions(+), 11 deletions(-)

New commits:
commit 6b49ef326a837026065dd203746f7715d8c379c4
Author: Ashod Nakashian 
Date:   Tue Jan 3 00:12:15 2017 -0500

wsd: better logging when adding/removing sessions

Change-Id: Ie11886390687c744e1a0f60bff4317898c36f9c2
Reviewed-on: https://gerrit.libreoffice.org/32675
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index a9a2dac..53ead02 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -621,11 +621,6 @@ size_t 
DocumentBroker::addSession(std::shared_ptr& session)
 _lastEditableSession = false;
 _markToDestroy = false;
 
-if (session->isReadOnly())
-{
-LOG_DBG("Adding a readonly session [" << id << "]");
-}
-
 if (!_sessions.emplace(id, session).second)
 {
 LOG_WRN("DocumentBroker: Trying to add already existing session.");
@@ -638,11 +633,15 @@ size_t 
DocumentBroker::addSession(std::shared_ptr& session)
 // Request a new session from the child kit.
 _childProcess->sendTextFrame(aMessage);
 
+// Now we are ready to bridge between the kit and client.
+session->bridgePrisonerSession();
+
 // Tell the admin console about this new doc
 Admin::instance().addDoc(_docKey, getPid(), getFilename(), id);
 
-// Now we are ready to bridge between the kit and client.
-session->bridgePrisonerSession();
+LOG_TRC("Added " << (session->isReadOnly() ? "readonly" : "non-readonly") 
<<
+" session [" << id << "] to docKey [" <<
+_docKey << "] to have " << count << " sessions.");
 
 return count;
 }
@@ -663,6 +662,16 @@ size_t DocumentBroker::removeSession(const std::string& id)
 // Let the child know the client has disconnected.
 const std::string msg("child-" + id + " disconnect");
 _childProcess->sendTextFrame(msg);
+
+const auto count = _sessions.size();
+LOG_TRC("Removed " << (it->second->isReadOnly() ? "readonly" : 
"non-readonly") <<
+" session [" << id << "] from docKey [" <<
+_docKey << "] to have " << count << " sessions.");
+return count;
+}
+else
+{
+LOG_TRC("Session [" << id << "] not found to remove from docKey [" 
<< _docKey << "]");
 }
 }
 catch (const std::exception& ex)
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index cd176da..13ab14f 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -1032,10 +1032,7 @@ private:
 }
 
 LOOLWSD::dumpEventTrace(docBroker->getJailId(), id, "NewSession: " 
+ uri);
-
-// Request the child to connect to us and add this session.
-const auto sessionsCount = docBroker->addSession(session);
-LOG_TRC(docKey << ", ws_sessions++: " << sessionsCount);
+docBroker->addSession(session);
 }
 catch (const std::exception& exc)
 {
@@ -1043,6 +1040,7 @@ private:
 
 std::unique_lock docBrokersLock(DocBrokersMutex);
 auto lock = docBroker->getLock();
+docBroker->removeSession(id);
 if (docBroker->getSessionsCount() == 0 || !docBroker->isAlive())
 {
 LOG_INF("Removing unloaded DocumentBroker for docKey [" << 
docKey << "].");
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits