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

2020-09-18 Thread Miklos Vajna (via logerrit)
 wsd/LOOLWSD.cpp |   14 +++---
 wsd/LOOLWSD.hpp |2 +-
 2 files changed, 8 insertions(+), 8 deletions(-)

New commits:
commit 92543758a7858dea4213a5557f4ec69c426f5235
Author: Miklos Vajna 
AuthorDate: Fri Sep 18 11:03:17 2020 +0200
Commit: Miklos Vajna 
CommitDate: Fri Sep 18 14:05:37 2020 +0200

wsd: mark these functions as static

So that it's more obvious that they don't even read the state of the
object.

Change-Id: I71d39bf3a20989c8fbf3410c2f1d2a98661c49d5
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/102986
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Miklos Vajna 

diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 2e37618d3..9d89727ae 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -2264,7 +2264,7 @@ public:
 }
 
 /// Does this address feature in the allowed hosts list.
-bool allowPostFrom(const std::string )
+static bool allowPostFrom(const std::string )
 {
 static bool init = false;
 static Util::RegexListMatcher hosts;
@@ -2627,7 +2627,7 @@ private:
 LOG_INF("Sent / response successfully.");
 }
 
-void handleFaviconRequest(const RequestDetails ,
+static void handleFaviconRequest(const RequestDetails ,
   const std::shared_ptr& socket)
 {
 assert(socket && "Must have a valid socket");
@@ -2701,7 +2701,7 @@ private:
 LOG_INF("Sent capabilities.json successfully.");
 }
 
-void handleClipboardRequest(const Poco::Net::HTTPRequest& request,
+static void handleClipboardRequest(const Poco::Net::HTTPRequest& request,
 Poco::MemoryInputStream& message,
 SocketDisposition ,
 const std::shared_ptr& socket)
@@ -2800,7 +2800,7 @@ private:
 }
 }
 
-void handleRobotsTxtRequest(const Poco::Net::HTTPRequest& request,
+static void handleRobotsTxtRequest(const Poco::Net::HTTPRequest& request,
 const std::shared_ptr& socket)
 {
 assert(socket && "Must have a valid socket");
@@ -3442,7 +3442,7 @@ private:
 }
 
 /// Lookup cached file content.
-const std::string& getFileContent(const std::string& filename)
+static const std::string& getFileContent(const std::string& filename)
 {
 const auto it = StaticFileContentCache.find(filename);
 if (it == StaticFileContentCache.end())
@@ -3650,7 +3650,7 @@ public:
 PrisonerPoll.insertNewSocket(findPrisonerServerPort());
 }
 
-void stopPrisoners()
+static void stopPrisoners()
 {
 PrisonerPoll.joinThread();
 }
@@ -3774,7 +3774,7 @@ private:
 
 /// Create a new server socket - accepted sockets will be added
 /// to the @clientSockets' poll when created with @factory.
-std::shared_ptr getServerSocket(ServerSocket::Type type, int 
port,
+static std::shared_ptr getServerSocket(ServerSocket::Type 
type, int port,
   SocketPoll ,
   const 
std::shared_ptr& factory)
 {
diff --git a/wsd/LOOLWSD.hpp b/wsd/LOOLWSD.hpp
index 7f1e05a27..1b831e250 100644
--- a/wsd/LOOLWSD.hpp
+++ b/wsd/LOOLWSD.hpp
@@ -427,7 +427,7 @@ protected:
 int main(const std::vector& args) override;
 
 /// Handle various global static destructors.
-void cleanup();
+static void cleanup();
 
 private:
 #if ENABLE_SSL
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2020-04-20 Thread Tor Lillqvist (via logerrit)
 wsd/LOOLWSD.cpp |   10 +++---
 wsd/LOOLWSD.hpp |6 +-
 2 files changed, 12 insertions(+), 4 deletions(-)

New commits:
commit 6b8456679f10afc01fa92726bb1b5caa211385d0
Author: Tor Lillqvist 
AuthorDate: Mon Apr 20 11:47:50 2020 +0300
Commit: Tor Lillqvist 
CommitDate: Mon Apr 20 11:17:29 2020 +0200

Surround some code that is unused in the mobile apps with #if !MOBILEAPP

Reduces the risk of starting to look into something that is actually
never used in the mobile apps, when your intent is to re-work
soemthing for the mobile apps.

Change-Id: I04c562758a1b336690c7adbfd32b260cf26d9f87
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/92554
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Tor Lillqvist 

diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 9ab86355a..d54788d49 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -696,11 +696,11 @@ inline std::string getServiceURI(const std::string , 
bool asAdmin = false)
 
 std::atomic LOOLWSD::NextConnectionId(1);
 
+#if !MOBILEAPP
 #ifndef KIT_IN_PROCESS
 std::atomic LOOLWSD::ForKitProcId(-1);
 std::shared_ptr LOOLWSD::ForKitProc;
 #endif
-#if !MOBILEAPP
 bool LOOLWSD::NoCapsForKit = false;
 bool LOOLWSD::NoSeccomp = false;
 bool LOOLWSD::AdminEnabled = true;
@@ -755,6 +755,7 @@ public:
 /// Check prisoners are still alive and balanced.
 void wakeupHook() override;
 
+#if !MOBILEAPP
 // Resets the forkit porcess object
 void setForKitProcess(const std::weak_ptr& forKitProc)
 {
@@ -790,6 +791,7 @@ public:
 
 private:
 std::weak_ptr _forKitProc;
+#endif
 };
 
 /// This thread listens for and accepts prisoner kit processes.
@@ -809,6 +811,8 @@ public:
 }
 };
 
+#if !MOBILEAPP
+
 void ForKitProcWSHandler::handleMessage(const std::vector )
 {
 LOG_TRC("ForKitProcWSHandler: handling incoming [" << 
LOOLProtocol::getAbbreviatedMessage([0], data.size()) << "].");
@@ -820,9 +824,7 @@ void ForKitProcWSHandler::handleMessage(const 
std::vector )
 int count = std::stoi(tokens[1]);
 if (count >= 0)
 {
-#if !MOBILEAPP
 Admin::instance().addSegFaultCount(count);
-#endif
 LOG_INF(count << " loolkit processes crashed with segmentation 
fault.");
 }
 else
@@ -836,6 +838,8 @@ void ForKitProcWSHandler::handleMessage(const 
std::vector )
 }
 }
 
+#endif
+
 LOOLWSD::LOOLWSD()
 {
 }
diff --git a/wsd/LOOLWSD.hpp b/wsd/LOOLWSD.hpp
index c391cc055..ea3f33f3d 100644
--- a/wsd/LOOLWSD.hpp
+++ b/wsd/LOOLWSD.hpp
@@ -181,6 +181,8 @@ public:
 std::shared_ptr _socket;
 };
 
+#if !MOBILEAPP
+
 class ForKitProcWSHandler: public WebSocketHandler
 {
 public:
@@ -203,6 +205,8 @@ public:
 }
 };
 
+#endif
+
 /// The Server class which is responsible for all
 /// external interactions.
 class LOOLWSD : public Poco::Util::ServerApplication
@@ -221,10 +225,10 @@ public:
 static bool AdminEnabled;
 #if ENABLE_DEBUG
 static bool SingleKit;
-#endif
 #endif
 static std::shared_ptr ForKitProc;
 static std::atomic ForKitProcId;
+#endif
 static bool DummyLOK;
 static std::string FuzzFileName;
 static std::string ConfigFile;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2020-03-16 Thread Michael Meeks (via logerrit)
 wsd/LOOLWSD.cpp |   58 
 wsd/LOOLWSD.hpp |4 +++
 2 files changed, 33 insertions(+), 29 deletions(-)

New commits:
commit 4d9d769d950e6555de4392fb10c82efa53002611
Author: Michael Meeks 
AuthorDate: Mon Mar 16 16:19:37 2020 +
Commit: Michael Meeks 
CommitDate: Mon Mar 16 19:36:42 2020 +0100

Expose disk space and session checks via LOOLWSD class.

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

diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index ecceaca34..177360dbc 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -256,8 +256,31 @@ inline void shutdownLimitReached(const 
std::shared_ptr
 }
 #endif
 
-inline void checkSessionLimitsAndWarnClients()
+#if !MOBILEAPP
+/// Internal implementation to alert all clients
+/// connected to any document.
+void alertAllUsersInternal(const std::string& msg)
+{
+std::lock_guard docBrokersLock(DocBrokersMutex);
+
+LOG_INF("Alerting all users: [" << msg << "]");
+
+if (UnitWSD::get().filterAlertAllusers(msg))
+return;
+
+for (auto& brokerIt : DocBrokers)
+{
+std::shared_ptr docBroker = brokerIt.second;
+docBroker->addCallback([msg, docBroker](){ 
docBroker->alertAllUsers(msg); });
+}
+}
+#endif
+
+} // end anonymous namespace
+
+void LOOLWSD::checkSessionLimitsAndWarnClients()
 {
+#if !ENABLE_SUPPORT_KEY
 #if !MOBILEAPP
 ssize_t docBrokerCount = DocBrokers.size() - 
ConvertToBroker::getInstanceCount();
 if (LOOLWSD::MaxDocuments < 1 &&
@@ -276,29 +299,10 @@ inline void checkSessionLimitsAndWarnClients()
 }
 }
 #endif
-}
-
-#if !MOBILEAPP
-/// Internal implementation to alert all clients
-/// connected to any document.
-void alertAllUsersInternal(const std::string& msg)
-{
-std::lock_guard docBrokersLock(DocBrokersMutex);
-
-LOG_INF("Alerting all users: [" << msg << "]");
-
-if (UnitWSD::get().filterAlertAllusers(msg))
-return;
-
-for (auto& brokerIt : DocBrokers)
-{
-std::shared_ptr docBroker = brokerIt.second;
-docBroker->addCallback([msg, docBroker](){ 
docBroker->alertAllUsers(msg); });
-}
-}
 #endif
+}
 
-static void checkDiskSpaceAndWarnClients(const bool cacheLastCheck)
+void LOOLWSD::checkDiskSpaceAndWarnClients(const bool cacheLastCheck)
 {
 #if !MOBILEAPP
 try
@@ -317,8 +321,6 @@ static void checkDiskSpaceAndWarnClients(const bool 
cacheLastCheck)
 #endif
 }
 
-}
-
 /// Remove dead and idle DocBrokers.
 /// The client of idle document should've greyed-out long ago.
 /// Returns true if at least one is removed.
@@ -378,7 +380,7 @@ static int forkChildren(const int number)
 
 if (number > 0)
 {
-checkDiskSpaceAndWarnClients(false);
+LOOLWSD::checkDiskSpaceAndWarnClients(false);
 
 #ifdef KIT_IN_PROCESS
 forkLibreOfficeKit(LOOLWSD::ChildRoot, LOOLWSD::SysTemplate, 
LOOLWSD::LoTemplate, LO_JAIL_SUBPATH, number);
@@ -2874,12 +2876,10 @@ private:
 // Add and load the session.
 docBroker->addSession(clientSession);
 
-checkDiskSpaceAndWarnClients(true);
-#if !ENABLE_SUPPORT_KEY
+LOOLWSD::checkDiskSpaceAndWarnClients(true);
 // Users of development versions get just an 
info
 // when reaching max documents or connections
-checkSessionLimitsAndWarnClients();
-#endif
+LOOLWSD::checkSessionLimitsAndWarnClients();
 }
 catch (const UnauthorizedRequestException& exc)
 {
diff --git a/wsd/LOOLWSD.hpp b/wsd/LOOLWSD.hpp
index 166de2817..383263314 100644
--- a/wsd/LOOLWSD.hpp
+++ b/wsd/LOOLWSD.hpp
@@ -191,6 +191,10 @@ public:
 /// child kit processes and cleans up DocBrokers.
 static void doHousekeeping();
 
+static void checkDiskSpaceAndWarnClients(const bool cacheLastCheck);
+
+static void checkSessionLimitsAndWarnClients();
+
 /// Close document with @docKey and a @message
 static void closeDocument(const std::string& docKey, const std::string& 
message);
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2020-02-29 Thread Jan Holesovsky (via logerrit)
 wsd/LOOLWSD.cpp |6 +-
 wsd/LOOLWSD.hpp |2 ++
 2 files changed, 7 insertions(+), 1 deletion(-)

New commits:
commit 09005eb1cf67b12dd0be7623646c2e900c81b241
Author: Jan Holesovsky 
AuthorDate: Fri Feb 28 14:55:42 2020 +0100
Commit: Michael Meeks 
CommitDate: Sat Feb 29 11:01:00 2020 +0100

android: Don't even try to read these values, seem to trigger an exception.

All the code that is using them is compiled out on Android anyway.

Change-Id: Ica349135202211ecdcb095bb82aa677f2dee19ba
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/89714
Tested-by: Michael Meeks 
Reviewed-by: Michael Meeks 

diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 5611edba5..61b9d8f09 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -213,7 +213,6 @@ static int careerSpanMs = 0;
 
 /// The timeout for a child to spawn, initially high, then reset to the 
default.
 int ChildSpawnTimeoutMs = CHILD_TIMEOUT_MS * 4;
-bool LOOLWSD::NoCapsForKit = false;
 std::atomic LOOLWSD::NumConnections;
 std::set LOOLWSD::EditFileExtensions;
 
@@ -699,8 +698,11 @@ std::atomic LOOLWSD::NextConnectionId(1);
 std::atomic LOOLWSD::ForKitWritePipe(-1);
 std::atomic LOOLWSD::ForKitProcId(-1);
 #endif
+#if !MOBILEAPP
+bool LOOLWSD::NoCapsForKit = false;
 bool LOOLWSD::NoSeccomp = false;
 bool LOOLWSD::AdminEnabled = true;
+#endif
 #ifdef FUZZER
 bool LOOLWSD::DummyLOK = false;
 std::string LOOLWSD::FuzzFileName;
@@ -1100,9 +1102,11 @@ void LOOLWSD::initialize(Application& self)
 LOOLWSD::MaxConnections = MAX_CONNECTIONS;
 LOOLWSD::MaxDocuments = MAX_DOCUMENTS;
 
+#if !MOBILEAPP
 NoSeccomp = !getConfigValue(conf, "security.seccomp", true);
 NoCapsForKit = !getConfigValue(conf, "security.capabilities", true);
 AdminEnabled = getConfigValue(conf, "admin_console.enable", true);
+#endif
 
 #if ENABLE_SUPPORT_KEY
 const std::string supportKeyString = getConfigValue(conf, 
"support_key", "");
diff --git a/wsd/LOOLWSD.hpp b/wsd/LOOLWSD.hpp
index d14b77ae5..204129d77 100644
--- a/wsd/LOOLWSD.hpp
+++ b/wsd/LOOLWSD.hpp
@@ -49,9 +49,11 @@ public:
 // so just keep these as statics.
 static std::atomic NextConnectionId;
 static unsigned int NumPreSpawnedChildren;
+#if !MOBILEAPP
 static bool NoCapsForKit;
 static bool NoSeccomp;
 static bool AdminEnabled;
+#endif
 static std::atomic ForKitWritePipe;
 static std::atomic ForKitProcId;
 static bool DummyLOK;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2019-08-20 Thread Tor Lillqvist (via logerrit)
 wsd/LOOLWSD.cpp |2 ++
 wsd/LOOLWSD.hpp |   10 ++
 2 files changed, 12 insertions(+)

New commits:
commit 1d3ac69ffd5e4024878d87409ccb87c83cbd37c3
Author: Tor Lillqvist 
AuthorDate: Tue Aug 20 11:20:22 2019 +0300
Commit: Tor Lillqvist 
CommitDate: Tue Aug 20 10:55:32 2019 +0200

Avoid some "RuntimeConstant instance read before being initialized" issues

(In the !ENABLE_SSL case.)

Possibly the SSL or not ifdeffery could be cleaned up a bit more.

Change-Id: I0c9b4e956dcd317d6622a7394044fed0c4f2d976
Reviewed-on: https://gerrit.libreoffice.org/77780
Reviewed-by: Tor Lillqvist 
Tested-by: Tor Lillqvist 

diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index dd62d2929..e0518479d 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -710,8 +710,10 @@ std::string LOOLWSD::ConfigDir = LOOLWSD_CONFIGDIR 
"/conf.d";
 std::string LOOLWSD::LogLevel = "trace";
 bool LOOLWSD::AnonymizeUserData = false;
 std::uint64_t LOOLWSD::AnonymizationSalt = 82589933;
+#if ENABLE_SSL
 Util::RuntimeConstant LOOLWSD::SSLEnabled;
 Util::RuntimeConstant LOOLWSD::SSLTermination;
+#endif
 unsigned LOOLWSD::MaxConnections;
 unsigned LOOLWSD::MaxDocuments;
 std::string LOOLWSD::OverrideWatermark;
diff --git a/wsd/LOOLWSD.hpp b/wsd/LOOLWSD.hpp
index 2e6c68e70..7c4103e3b 100644
--- a/wsd/LOOLWSD.hpp
+++ b/wsd/LOOLWSD.hpp
@@ -92,12 +92,20 @@ public:
 
 static bool isSSLEnabled()
 {
+#if ENABLE_SSL
 return LOOLWSD::SSLEnabled.get();
+#else
+return false;
+#endif
 }
 
 static bool isSSLTermination()
 {
+#if ENABLE_SSL
 return LOOLWSD::SSLTermination.get();
+#else
+return false;
+#endif
 }
 
 /// Return true iff extension is marked as view action in discovery.xml.
@@ -182,8 +190,10 @@ protected:
 void cleanup();
 
 private:
+#if ENABLE_SSL
 static Util::RuntimeConstant SSLEnabled;
 static Util::RuntimeConstant SSLTermination;
+#endif
 
 void initializeSSL();
 void displayHelp();
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

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

2017-07-17 Thread Jan Holesovsky
 wsd/LOOLWSD.cpp |6 +++---
 wsd/LOOLWSD.hpp |4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

New commits:
commit 92cdab8bf8ea1a72e1745b88e9e31b59560e6f7b
Author: Jan Holesovsky 
Date:   Mon Jul 17 19:59:46 2017 +0200

discovery: Make the unknown file extensions read-only.

Change-Id: Ie1467334868a7e4aa31aa69f67d0cd434ed18e7b
Reviewed-on: https://gerrit.libreoffice.org/40083
Reviewed-by: Jan Holesovsky 
Tested-by: Jan Holesovsky 

diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 83f34ac5..2852fb7a 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -553,7 +553,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;
+std::set LOOLWSD::EditFileExtensions;
 
 static std::string UnitTestLibrary;
 
@@ -2233,8 +2233,8 @@ private:
 elem->setAttribute(urlsrc, uriValue);
 
 // Set the View extensions cache as well.
-if (elem->getAttribute("name") == "view")
-LOOLWSD::ViewFileExtensions.insert(elem->getAttribute("ext"));
+if (elem->getAttribute("name") == "edit")
+LOOLWSD::EditFileExtensions.insert(elem->getAttribute("ext"));
 }
 
 std::ostringstream ostrXML;
diff --git a/wsd/LOOLWSD.hpp b/wsd/LOOLWSD.hpp
index 7ed29e15..86f8dbcb 100644
--- a/wsd/LOOLWSD.hpp
+++ b/wsd/LOOLWSD.hpp
@@ -55,7 +55,7 @@ public:
 static std::atomic NumConnections;
 static bool TileCachePersistent;
 static std::unique_ptr TraceDumper;
-static std::set ViewFileExtensions;
+static std::set EditFileExtensions;
 
 /// Flag to shutdown the server.
 std::atomic ShutdownFlag;
@@ -85,7 +85,7 @@ public:
 /// 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();
+return EditFileExtensions.find(extension) == EditFileExtensions.end();
 }
 
 /// Returns the value of the specified application configuration,
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

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

New commits:
commit 63dd8fca9b117f502e2145619dfc71342f822f32
Author: Ashod Nakashian 
Date:   Sun Jan 15 20:12:10 2017 -0500

wsd: improved forkit crash recovery

Refactored the forkit process wait and
re-fork into separate function.

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

diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index ac89bdd..c9f9e7c 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -330,6 +330,8 @@ static bool forkChildren(const int number)
 LastForkRequestTime = std::chrono::steady_clock::now();
 return true;
 }
+
+LOG_ERR("No forkit pipe while rebalancing children.");
 }
 
 return false;
@@ -476,6 +478,7 @@ static std::shared_ptr getNewChild()
 if (!rebalanceChildren(numPreSpawn))
 {
 // Fatal. Let's fail and retry at a higher level.
+LOG_DBG("getNewChild: rebalancing of children failed.");
 return nullptr;
 }
 
@@ -869,6 +872,7 @@ private:
 if (retry > 0)
 {
 LOG_WRN("Failed to connect DocBroker and Client Session, 
retrying.");
+LOOLWSD::checkAndRestoreForKit();
 }
 else
 {
@@ -2076,14 +2080,80 @@ void LOOLWSD::displayHelp()
 helpFormatter.format(std::cout);
 }
 
+bool LOOLWSD::checkAndRestoreForKit()
+{
+int status;
+const pid_t pid = waitpid(ForKitProcId, , WUNTRACED | WNOHANG);
+if (pid > 0)
+{
+if (pid == ForKitProcId)
+{
+if (WIFEXITED(status) || WIFSIGNALED(status))
+{
+if (WIFEXITED(status))
+{
+LOG_INF("Forkit process [" << pid << "] exited with code: 
" <<
+WEXITSTATUS(status) << ".");
+}
+else
+{
+LOG_ERR("Forkit process [" << pid << "] " <<
+(WCOREDUMP(status) ? "core-dumped" : "died") <<
+" with " << SigUtil::signalName(WTERMSIG(status)));
+}
+
+// Spawn a new forkit and try to dust it off and resume.
+if (!createForKit())
+{
+LOG_FTL("Failed to spawn forkit instance. Shutting down.");
+SigUtil::requestShutdown();
+}
+}
+else if (WIFSTOPPED(status))
+{
+LOG_INF("Forkit process [" << pid << "] stopped with " <<
+SigUtil::signalName(WSTOPSIG(status)));
+}
+else if (WIFCONTINUED(status))
+{
+LOG_INF("Forkit process [" << pid << "] resumed with 
SIGCONT.");
+}
+else
+{
+LOG_WRN("Unknown status returned by waitpid: " << std::hex << 
status << ".");
+}
+
+return true;
+}
+else
+{
+LOG_ERR("An unknown child process [" << pid << "] died.");
+}
+}
+else if (pid < 0)
+{
+LOG_SYS("Forkit waitpid failed.");
+if (errno == ECHILD)
+{
+// No child processes.
+// Spawn a new forkit and try to dust it off and resume.
+if (!createForKit())
+{
+LOG_FTL("Failed to spawn forkit instance. Shutting down.");
+SigUtil::requestShutdown();
+}
+}
+
+return true;
+}
+
+return false;
+}
+
 bool LOOLWSD::createForKit()
 {
 LOG_INF("Creating new forkit process.");
 
-const int oldForKitWritePipe = ForKitWritePipe;
-ForKitWritePipe = -1;
-close(oldForKitWritePipe);
-
 Process::Args args;
 args.push_back("--losubpath=" + std::string(LO_JAIL_SUBPATH));
 args.push_back("--systemplate=" + SysTemplate);
@@ -2092,9 +2162,14 @@ bool LOOLWSD::createForKit()
 args.push_back("--clientport=" + std::to_string(ClientPortNumber));
 args.push_back("--masterport=" + std::to_string(MasterPortNumber));
 if (UnitWSD::get().hasKitHooks())
+{
 args.push_back("--unitlib=" + UnitTestLibrary);
+}
+
 if (DisplayVersion)
+{
 args.push_back("--version");
+}
 
 std::string forKitPath = 
Path(Application::instance().commandPath()).parent().toString() + "loolforkit";
 if (NoCapsForKit)
@@ -2107,6 +2182,15 @@ bool LOOLWSD::createForKit()
 std::unique_lock docBrokersLock(DocBrokersMutex);
 std::unique_lock newChildrenLock(NewChildrenMutex);
 
+// Always reap first, in 

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

2017-01-15 Thread Ashod Nakashian
 wsd/LOOLWSD.cpp |   30 ++
 wsd/LOOLWSD.hpp |6 +-
 2 files changed, 19 insertions(+), 17 deletions(-)

New commits:
commit bccb2fcad69bd562db4e17eb6aba0ad5be417206
Author: Ashod Nakashian 
Date:   Sun Jan 15 17:54:55 2017 -0500

wsd: forkit process id is now a static member

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

diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 23507ff..ac89bdd 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -1678,6 +1678,7 @@ inline std::string getAdminURI(const 
Poco::Util::LayeredConfiguration )
 
 std::atomic LOOLWSD::NextSessionId;
 std::atomic LOOLWSD::ForKitWritePipe(-1);
+std::atomic LOOLWSD::ForKitProcId(-1);
 bool LOOLWSD::NoCapsForKit = false;
 std::string LOOLWSD::Cache = LOOLWSD_CACHEDIR;
 std::string LOOLWSD::SysTemplate;
@@ -2075,7 +2076,7 @@ void LOOLWSD::displayHelp()
 helpFormatter.format(std::cout);
 }
 
-Process::PID LOOLWSD::createForKit()
+bool LOOLWSD::createForKit()
 {
 LOG_INF("Creating new forkit process.");
 
@@ -2120,17 +2121,17 @@ Process::PID LOOLWSD::createForKit()
 // The Pipe dtor closes the fd, so dup it.
 ForKitWritePipe = dup(inPipe.writeHandle());
 
-const auto forkitPid = child.id();
+ForKitProcId = child.id();
 
-LOG_INF("Forkit process launched: " << forkitPid);
+LOG_INF("Forkit process launched: " << ForKitProcId);
 
 // Init the Admin manager
-Admin::instance().setForKitPid(forkitPid);
+Admin::instance().setForKitPid(ForKitProcId);
 
 // Spawn some children, if necessary.
 preForkChildren(newChildrenLock);
 
-return forkitPid;
+return (ForKitProcId != -1);
 }
 
 int LOOLWSD::main(const std::vector& /*args*/)
@@ -2230,8 +2231,7 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 srv2.start();
 
 // Fire the ForKit process; we are ready to get child connections.
-Process::PID forKitPid = createForKit();
-if (forKitPid < 0)
+if (!createForKit())
 {
 LOG_FTL("Failed to spawn loolforkit.");
 return Application::EXIT_SOFTWARE;
@@ -2268,10 +2268,10 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 break;
 }
 
-const pid_t pid = waitpid(forKitPid, , WUNTRACED | WNOHANG);
+const pid_t pid = waitpid(ForKitProcId, , WUNTRACED | WNOHANG);
 if (pid > 0)
 {
-if (forKitPid == pid)
+if (ForKitProcId == pid)
 {
 if (WIFEXITED(status) || WIFSIGNALED(status))
 {
@@ -2288,8 +2288,7 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 }
 
 // Spawn a new forkit and try to dust it off and resume.
-forKitPid = createForKit();
-if (forKitPid < 0)
+if (!createForKit())
 {
 LOG_FTL("Failed to spawn forkit instance. Shutting 
down.");
 SigUtil::requestShutdown();
@@ -2322,8 +2321,7 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 {
 // No child processes.
 // Spawn a new forkit and try to dust it off and resume.
-forKitPid = createForKit();
-if (forKitPid < 0)
+if (!createForKit())
 {
 LOG_FTL("Failed to spawn forkit instance. Shutting down.");
 SigUtil::requestShutdown();
@@ -2390,8 +2388,8 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 DocBrokers.clear();
 
 // Terminate child processes
-LOG_INF("Requesting forkit process " << forKitPid << " to terminate.");
-SigUtil::killChild(forKitPid);
+LOG_INF("Requesting forkit process " << ForKitProcId << " to terminate.");
+SigUtil::killChild(ForKitProcId);
 
 // Terminate child processes
 LOG_INF("Requesting child processes to terminate.");
@@ -2401,7 +2399,7 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 }
 
 // Wait for forkit process finish.
-waitpid(forKitPid, , WUNTRACED);
+waitpid(ForKitProcId, , WUNTRACED);
 close(ForKitWritePipe);
 
 // In case forkit didn't cleanup properly, don't leave jails behind.
diff --git a/wsd/LOOLWSD.hpp b/wsd/LOOLWSD.hpp
index 7728efa..f802981 100644
--- a/wsd/LOOLWSD.hpp
+++ b/wsd/LOOLWSD.hpp
@@ -37,6 +37,7 @@ public:
 static unsigned int NumPreSpawnedChildren;
 static bool NoCapsForKit;
 static std::atomic ForKitWritePipe;
+static std::atomic ForKitProcId;
 static std::string Cache;
 static std::string SysTemplate;
 static std::string LoTemplate;
@@ -68,6 +69,10 @@ public:
 
 static void dumpOutgoingTrace(const std::string& id, const std::string& 
sessionId, const std::string& data);
 
+/// Creates a 

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

2017-01-15 Thread Ashod Nakashian
 wsd/LOOLWSD.cpp |   19 +--
 wsd/LOOLWSD.hpp |2 +-
 2 files changed, 14 insertions(+), 7 deletions(-)

New commits:
commit e3aec0e6c4b7fefe65aff19e6eb1ac048f2c8306
Author: Ashod Nakashian 
Date:   Sun Jan 15 12:57:22 2017 -0500

wsd: detect and fail child forking when forkit is down

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

diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 47a2fdc..7d55971 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -389,7 +389,7 @@ static bool rebalanceChildren(int balance)
 return forkChildren(balance);
 }
 
-return false;
+return true;
 }
 
 /// Called on startup only.
@@ -473,7 +473,11 @@ static std::shared_ptr getNewChild()
 LOG_DBG("getNewChild: Rebalancing children.");
 int numPreSpawn = LOOLWSD::NumPreSpawnedChildren;
 ++numPreSpawn; // Replace the one we'll dispatch just now.
-rebalanceChildren(numPreSpawn);
+if (!rebalanceChildren(numPreSpawn))
+{
+// Fatal. Let's fail and retry at a higher level.
+return nullptr;
+}
 
 LOG_TRC("Waiting for a new child for a max of " << CHILD_TIMEOUT_MS << 
" ms.");
 const auto timeout = chrono::milliseconds(CHILD_TIMEOUT_MS);
@@ -1673,7 +1677,7 @@ inline std::string getAdminURI(const 
Poco::Util::LayeredConfiguration )
 } // anonymous namespace
 
 std::atomic LOOLWSD::NextSessionId;
-int LOOLWSD::ForKitWritePipe = -1;
+std::atomic LOOLWSD::ForKitWritePipe(-1);
 bool LOOLWSD::NoCapsForKit = false;
 std::string LOOLWSD::Cache = LOOLWSD_CACHEDIR;
 std::string LOOLWSD::SysTemplate;
@@ -2073,8 +2077,13 @@ void LOOLWSD::displayHelp()
 
 Process::PID LOOLWSD::createForKit()
 {
-Process::Args args;
+LOG_INF("Creating new forkit process.");
+
+const int oldForKitWritePipe = ForKitWritePipe;
+ForKitWritePipe = -1;
+close(oldForKitWritePipe);
 
+Process::Args args;
 args.push_back("--losubpath=" + std::string(LO_JAIL_SUBPATH));
 args.push_back("--systemplate=" + SysTemplate);
 args.push_back("--lotemplate=" + LoTemplate);
@@ -2271,7 +2280,6 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 }
 
 // Spawn a new forkit and try to dust it off and resume.
-close(ForKitWritePipe);
 forKitPid = createForKit();
 if (forKitPid < 0)
 {
@@ -2306,7 +2314,6 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 {
 // No child processes.
 // Spawn a new forkit and try to dust it off and resume.
-close(ForKitWritePipe);
 forKitPid = createForKit();
 if (forKitPid < 0)
 {
diff --git a/wsd/LOOLWSD.hpp b/wsd/LOOLWSD.hpp
index a8d364e..7728efa 100644
--- a/wsd/LOOLWSD.hpp
+++ b/wsd/LOOLWSD.hpp
@@ -36,7 +36,7 @@ public:
 static std::atomic NextSessionId;
 static unsigned int NumPreSpawnedChildren;
 static bool NoCapsForKit;
-static int ForKitWritePipe;
+static std::atomic ForKitWritePipe;
 static std::string Cache;
 static std::string SysTemplate;
 static std::string LoTemplate;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits