[Libreoffice-commits] online.git: loolwsd/ChildProcessSession.cpp loolwsd/Common.hpp loolwsd/Connect.cpp loolwsd/LoadTest.cpp loolwsd/LOOLBroker.cpp loolwsd/LOOLSession.cpp loolwsd/LOOLWSD.cpp loolwsd/LOOLWSD.hpp loolwsd/MasterProcessSession.cpp loolwsd/Util.hpp
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Mon Dec 28 15:37:15 PST 2015
loolwsd/ChildProcessSession.cpp | 1
loolwsd/Common.hpp | 10 +++----
loolwsd/Connect.cpp | 1
loolwsd/LOOLBroker.cpp | 11 ++------
loolwsd/LOOLSession.cpp | 1
loolwsd/LOOLWSD.cpp | 53 +++++++++++----------------------------
loolwsd/LOOLWSD.hpp | 10 ++-----
loolwsd/LoadTest.cpp | 1
loolwsd/MasterProcessSession.cpp | 4 +-
loolwsd/Util.hpp | 1
10 files changed, 29 insertions(+), 64 deletions(-)
New commits:
commit 88b76fe9d425638e2b7227338a6834a4b7f4292f
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Mon Dec 28 16:34:21 2015 -0500
loolwsd: removed dead code
Variables and options lingering from previous iterations removed.
Standardizing static member names.
Header inclusion cleanups.
Change-Id: I65182ad4d100e0077f1b450be50cf95d7b8f0fc7
Reviewed-on: https://gerrit.libreoffice.org/20997
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/loolwsd/ChildProcessSession.cpp b/loolwsd/ChildProcessSession.cpp
index 2fce67a..4fd6351 100644
--- a/loolwsd/ChildProcessSession.cpp
+++ b/loolwsd/ChildProcessSession.cpp
@@ -23,7 +23,6 @@
#include "ChildProcessSession.hpp"
#include "LOKitHelper.hpp"
#include "LOOLProtocol.hpp"
-#include "LOOLWSD.hpp"
#include "Util.hpp"
using namespace LOOLProtocol;
diff --git a/loolwsd/Common.hpp b/loolwsd/Common.hpp
index fba45a4..4ab5e8c 100644
--- a/loolwsd/Common.hpp
+++ b/loolwsd/Common.hpp
@@ -11,11 +11,11 @@
#ifndef INCLUDED_COMMON_HPP
#define INCLUDED_COMMON_HPP
-static const int DEFAULT_CLIENT_PORT_NUMBER = 9980;
-static const int MASTER_PORT_NUMBER = 9981;
-static const int INTERVAL_PROBES = 10;
-static const int MAINTENANCE_INTERVAL = 1;
-static const int POLL_TIMEOUT = 1000000;
+constexpr int DEFAULT_CLIENT_PORT_NUMBER = 9980;
+constexpr int MASTER_PORT_NUMBER = 9981;
+constexpr int INTERVAL_PROBES = 10;
+constexpr int MAINTENANCE_INTERVAL = 1;
+constexpr int POLL_TIMEOUT = 1000000;
// The client port number, which is changed via loolwsd args.
static int ClientPortNumber = DEFAULT_CLIENT_PORT_NUMBER;
diff --git a/loolwsd/Connect.cpp b/loolwsd/Connect.cpp
index 4a74663..2f81a67 100644
--- a/loolwsd/Connect.cpp
+++ b/loolwsd/Connect.cpp
@@ -34,7 +34,6 @@
#include "Common.hpp"
#include "LOOLProtocol.hpp"
-#include "LOOLWSD.hpp"
#include "Util.hpp"
using namespace LOOLProtocol;
diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp
index 836ef1d..0351739 100644
--- a/loolwsd/LOOLBroker.cpp
+++ b/loolwsd/LOOLBroker.cpp
@@ -42,9 +42,6 @@
#define LOOLKIT_NO_MAIN 1
#include "LOOLKit.cpp"
-#define INTERVAL_PROBES 10
-#define MAINTENANCE_INTERVAL 1
-
#define LIB_SOFFICEAPP "lib" "sofficeapp" ".so"
#define LIB_SCLO "lib" "sclo" ".so"
#define LIB_SWLO "lib" "swlo" ".so"
@@ -66,7 +63,6 @@ const std::string BROKER_PREFIX = "/tmp/lokit";
static int readerChild = -1;
static int readerBroker = -1;
-static int timeoutCounter = 0;
static unsigned int forkCounter = 0;
static unsigned int childCounter = 0;
@@ -76,8 +72,6 @@ static std::deque<Process::PID> _emptyURL;
static std::map<Process::PID, int> _childProcesses;
static std::map<std::string, Process::PID> _cacheURL;
-Poco::NamedMutex _namedMutexLOOL("loolwsd");
-
namespace
{
ThreadLocal<std::string> sourceForLinkOrCopy;
@@ -800,6 +794,8 @@ int main(int argc, char** argv)
Log::info("loolbroker ready!");
+
+ unsigned timeoutCounter = 0;
while (_childProcesses.size() > 0)
{
int status;
@@ -849,8 +845,7 @@ int main(int argc, char** argv)
forkMutex.unlock();
}
- ++timeoutCounter;
- if (timeoutCounter == INTERVAL_PROBES)
+ if (timeoutCounter++ == INTERVAL_PROBES)
{
timeoutCounter = 0;
sleep(MAINTENANCE_INTERVAL);
diff --git a/loolwsd/LOOLSession.cpp b/loolwsd/LOOLSession.cpp
index 52bb451..2f642ed 100644
--- a/loolwsd/LOOLSession.cpp
+++ b/loolwsd/LOOLSession.cpp
@@ -52,7 +52,6 @@
#include "LOOLProtocol.hpp"
#include "LOOLSession.hpp"
-#include "LOOLWSD.hpp"
#include "TileCache.hpp"
#include "Util.hpp"
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index c1175bf..e66d872 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -212,7 +212,6 @@ namespace
#endif
// Running under sudo, probably because being debugged? Let's drop super-user rights.
- LOOLWSD::runningAsRoot = true;
if (LOOLWSD::uid == 0)
{
struct passwd *nobody = getpwnam("nobody");
@@ -668,22 +667,18 @@ private:
};
std::atomic<unsigned> LOOLWSD::NextSessionId;
-int LOOLWSD::timeoutCounter = 0;
-int LOOLWSD::writerBroker = -1;
-Poco::UInt64 LOOLWSD::_childId = 0;
+int LOOLWSD::BrokerWritePipe = -1;
std::string LOOLWSD::cache = LOOLWSD_CACHEDIR;
std::string LOOLWSD::sysTemplate;
std::string LOOLWSD::loTemplate;
std::string LOOLWSD::childRoot;
std::string LOOLWSD::loSubPath = "lo";
-std::string LOOLWSD::jail;
-Poco::NamedMutex LOOLWSD::_namedMutexLOOL("loolwsd");
+Poco::NamedMutex LOOLWSD::NamedMutexLOOL("loolwsd");
-int LOOLWSD::_numPreSpawnedChildren = 10;
+int LOOLWSD::NumPreSpawnedChildren = 10;
bool LOOLWSD::doTest = false;
volatile bool LOOLWSD::isShutDown = false;
#if ENABLE_DEBUG
-bool LOOLWSD::runningAsRoot = false;
int LOOLWSD::uid = 0;
#endif
const std::string LOOLWSD::CHILD_URI = "/loolws/child/";
@@ -779,16 +774,6 @@ void LOOLWSD::defineOptions(OptionSet& optionSet)
.required(false)
.repeatable(false));
- optionSet.addOption(Option("child", "", "For internal use only.")
- .required(false)
- .repeatable(false)
- .argument("child id"));
-
- optionSet.addOption(Option("jail", "", "For internal use only.")
- .required(false)
- .repeatable(false)
- .argument("directory"));
-
#if ENABLE_DEBUG
optionSet.addOption(Option("uid", "", "Uid to assume if running under sudo for debugging purposes.")
.required(false)
@@ -819,13 +804,9 @@ void LOOLWSD::handleOption(const std::string& optionName, const std::string& val
else if (optionName == "losubpath")
loSubPath = value;
else if (optionName == "numprespawns")
- _numPreSpawnedChildren = std::stoi(value);
+ NumPreSpawnedChildren = std::stoi(value);
else if (optionName == "test")
LOOLWSD::doTest = true;
- else if (optionName == "child")
- _childId = std::stoull(value);
- else if (optionName == "jail")
- jail = value;
#if ENABLE_DEBUG
else if (optionName == "uid")
uid = std::stoull(value);
@@ -849,7 +830,7 @@ int LOOLWSD::createBroker()
args.push_back("--systemplate=" + sysTemplate);
args.push_back("--lotemplate=" + loTemplate);
args.push_back("--childroot=" + childRoot);
- args.push_back("--numprespawns=" + std::to_string(_numPreSpawnedChildren));
+ args.push_back("--numprespawns=" + std::to_string(NumPreSpawnedChildren));
args.push_back("--clientport=" + std::to_string(ClientPortNumber));
std::string executable = Path(Application::instance().commandPath()).parent().toString() + "loolbroker";
@@ -907,15 +888,11 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
if (childRoot == "")
throw MissingOptionException("childroot");
- if (_childId != 0)
- throw IncompatibleOptionsException("child");
- if (jail != "")
- throw IncompatibleOptionsException("jail");
if (ClientPortNumber == MASTER_PORT_NUMBER)
throw IncompatibleOptionsException("port");
if (LOOLWSD::doTest)
- _numPreSpawnedChildren = 1;
+ NumPreSpawnedChildren = 1;
// log pid information
{
@@ -930,7 +907,7 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
return Application::EXIT_UNAVAILABLE;
}
- _namedMutexLOOL.lock();
+ NamedMutexLOOL.lock();
startupBroker(1);
@@ -943,27 +920,27 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
#endif
// Start a server listening on the port for clients
- ServerSocket svs(ClientPortNumber, _numPreSpawnedChildren*10);
- ThreadPool threadPool(_numPreSpawnedChildren*2, _numPreSpawnedChildren*5);
+ ServerSocket svs(ClientPortNumber, NumPreSpawnedChildren*10);
+ ThreadPool threadPool(NumPreSpawnedChildren*2, NumPreSpawnedChildren*5);
HTTPServer srv(new RequestHandlerFactory(), threadPool, svs, new HTTPServerParams);
srv.start();
// And one on the port for child processes
SocketAddress addr2("127.0.0.1", MASTER_PORT_NUMBER);
- ServerSocket svs2(addr2, _numPreSpawnedChildren);
- ThreadPool threadPool2(_numPreSpawnedChildren*2, _numPreSpawnedChildren*5);
+ ServerSocket svs2(addr2, NumPreSpawnedChildren);
+ ThreadPool threadPool2(NumPreSpawnedChildren*2, NumPreSpawnedChildren*5);
HTTPServer srv2(new RequestHandlerFactory(), threadPool2, svs2, new HTTPServerParams);
srv2.start();
- if ( (writerBroker = open(FIFO_FILE.c_str(), O_WRONLY) ) < 0 )
+ if ( (BrokerWritePipe = open(FIFO_FILE.c_str(), O_WRONLY) ) < 0 )
{
Log::error("Error: failed to open pipe [" + FIFO_FILE + "] write only.");
return Application::EXIT_UNAVAILABLE;
}
- _namedMutexLOOL.unlock();
+ NamedMutexLOOL.unlock();
TestInput input(*this, svs, srv);
Thread inputThread;
@@ -973,6 +950,7 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
waitForTerminationRequest();
}
+ unsigned timeoutCounter = 0;
while (!LOOLWSD::isShutDown && !LOOLWSD::doTest && MasterProcessSession::_childProcesses.size() > 0)
{
pid_t pid = waitpid(-1, &status, WUNTRACED | WNOHANG);
@@ -1006,8 +984,7 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
else if (pid < 0)
Log::error("Error: Child error.");
- ++timeoutCounter;
- if (timeoutCounter == INTERVAL_PROBES)
+ if (timeoutCounter++ == INTERVAL_PROBES)
{
timeoutCounter = 0;
sleep(MAINTENANCE_INTERVAL*2);
diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp
index 7da3fa4..aa16abd 100644
--- a/loolwsd/LOOLWSD.hpp
+++ b/loolwsd/LOOLWSD.hpp
@@ -34,9 +34,8 @@ public:
// An Application is a singleton anyway, so just keep these as
// statics
static std::atomic<unsigned> NextSessionId;
- static int timeoutCounter;
- static int _numPreSpawnedChildren;
- static int writerBroker;
+ static int NumPreSpawnedChildren;
+ static int BrokerWritePipe;
static bool doTest;
static bool volatile isShutDown;
static std::string cache;
@@ -44,9 +43,7 @@ public:
static std::string loTemplate;
static std::string childRoot;
static std::string loSubPath;
- static std::string jail;
- static Poco::NamedMutex _namedMutexLOOL;
- static Poco::UInt64 _childId;
+ static Poco::NamedMutex NamedMutexLOOL;
static const std::string CHILD_URI;
static const std::string PIDLOG;
@@ -83,7 +80,6 @@ private:
#if ENABLE_DEBUG
public:
- static bool runningAsRoot;
static int uid;
#endif
};
diff --git a/loolwsd/LoadTest.cpp b/loolwsd/LoadTest.cpp
index 988b9e4..4fdc245 100644
--- a/loolwsd/LoadTest.cpp
+++ b/loolwsd/LoadTest.cpp
@@ -41,7 +41,6 @@
#include "Common.hpp"
#include "LoadTest.hpp"
#include "LOOLProtocol.hpp"
-#include "LOOLWSD.hpp"
#include "Util.hpp"
using namespace LOOLProtocol;
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index 5537ca6..e56ed1c 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -385,7 +385,7 @@ bool MasterProcessSession::loadDocument(const char* /*buffer*/, int /*length*/,
// request new URL session
const std::string aMessage = "request " + getId() + " " + _docURL + "\r\n";
Log::info("Sending to Broker: " + aMessage);
- Util::writeFIFO(LOOLWSD::writerBroker, aMessage.c_str(), aMessage.length());
+ Util::writeFIFO(LOOLWSD::BrokerWritePipe, aMessage.c_str(), aMessage.length());
}
catch (const Poco::SyntaxException&)
{
@@ -583,7 +583,7 @@ void MasterProcessSession::dispatchChild()
Log::info() << "Retrying child permission... " << nRequest << Log::end;
// request again new URL session
const std::string aMessage = "request " + getId() + " " + _docURL + "\r\n";
- Util::writeFIFO(LOOLWSD::writerBroker, aMessage.c_str(), aMessage.length());
+ Util::writeFIFO(LOOLWSD::BrokerWritePipe, aMessage.c_str(), aMessage.length());
}
}
diff --git a/loolwsd/Util.hpp b/loolwsd/Util.hpp
index 6df29e3..89bf7a8 100644
--- a/loolwsd/Util.hpp
+++ b/loolwsd/Util.hpp
@@ -12,6 +12,7 @@
#include <string>
#include <sstream>
+#include <functional>
#include <Poco/File.h>
#include <Poco/Path.h>
More information about the Libreoffice-commits
mailing list