[Libreoffice-commits] online.git: loolwsd/LOOLBroker.cpp loolwsd/LOOLWSD.cpp loolwsd/MasterProcessSession.cpp loolwsd/MasterProcessSession.hpp
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Mon Jan 4 17:13:01 PST 2016
loolwsd/LOOLBroker.cpp | 9 +++++----
loolwsd/LOOLWSD.cpp | 5 +++--
loolwsd/MasterProcessSession.cpp | 25 +++++++++++++++----------
loolwsd/MasterProcessSession.hpp | 7 ++++---
4 files changed, 27 insertions(+), 19 deletions(-)
New commits:
commit 75c65af9306dfdcca2897e9cec5365f8c9c0e230
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Sun Jan 3 14:52:32 2016 -0500
loolwsd: childId is now string
Change-Id: I7037c03d2b40ff88deed0619e8a34ce5434913a3
Reviewed-on: https://gerrit.libreoffice.org/21095
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp
index 169e725..75a3395 100644
--- a/loolwsd/LOOLBroker.cpp
+++ b/loolwsd/LOOLBroker.cpp
@@ -655,7 +655,8 @@ int main(int argc, char** argv)
exit(-1);
}
- const std::string childId = std::to_string(Util::rng::getNext());
+ //TODO: Why not use our PID?
+ const std::string childId = Util::encodeId(Util::rng::getNext());
const Path jailPath = Path::forDirectory(childRoot + Path::separator() + childId);
Log::info("Jail path: " + jailPath.toString());
@@ -674,10 +675,10 @@ int main(int argc, char** argv)
File(loolkitPath).copyTo(Path(jailPath, JAILED_LOOLKIT_PATH).toString());
// We need this because sometimes the hostname is not resolved
- std::vector<std::string> networkFiles = {"/etc/host.conf", "/etc/hosts", "/etc/nsswitch.conf", "/etc/resolv.conf"};
- for (std::vector<std::string>::iterator it = networkFiles.begin(); it != networkFiles.end(); ++it)
+ const std::vector<std::string> networkFiles = {"/etc/host.conf", "/etc/hosts", "/etc/nsswitch.conf", "/etc/resolv.conf"};
+ for (const auto& filename : networkFiles)
{
- File networkFile(*it);
+ const File networkFile(filename);
if (networkFile.exists())
{
networkFile.copyTo(Path(jailPath, "/etc").toString());
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index f21bfd4..e41ec2a 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -310,8 +310,9 @@ public:
Poco::Net::HTMLForm form(request, request.stream(), handler);
if (form.has("childid") && form.has("name"))
{
- std::string dirPath = LOOLWSD::childRoot + Path::separator() + form.get("childid") + LOOLSession::jailDocumentURL +
- Path::separator() + "insertfile";
+ const std::string dirPath = LOOLWSD::childRoot + Path::separator() + form.get("childid")
+ + LOOLSession::jailDocumentURL
+ + Path::separator() + "insertfile";
File(dirPath).createDirectory();
std::string fileName = dirPath + Path::separator() + form.get("name");
File(tmpPath).moveTo(fileName);
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index 2d5478d..dd66fc2 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -52,7 +52,6 @@ MasterProcessSession::MasterProcessSession(const std::string& id,
const Kind kind,
std::shared_ptr<Poco::Net::WebSocket> ws) :
LOOLSession(id, kind, ws),
- _childId(0),
_pidChild(0),
_curPart(0),
_loadPart(-1)
@@ -212,7 +211,7 @@ bool MasterProcessSession::_handleInput(const char *buffer, int length)
return false;
}
- const UInt64 childId = std::stoull(tokens[1]);
+ const auto childId = tokens[1];
setId(tokens[2]);
const Process::PID pidChild = std::stoull(tokens[3]);
@@ -336,12 +335,12 @@ bool MasterProcessSession::_handleInput(const char *buffer, int length)
bool MasterProcessSession::haveSeparateProcess()
{
- return _childId != 0;
+ return !_childId.empty();
}
-Path MasterProcessSession::getJailPath(UInt64 childId)
+Poco::Path MasterProcessSession::getJailPath(const std::string& childId)
{
- return Path::forDirectory(LOOLWSD::childRoot + Path::separator() + std::to_string(childId));
+ return Path::forDirectory(LOOLWSD::childRoot + Path::separator() + childId);
}
bool MasterProcessSession::invalidateTiles(const char* /*buffer*/, int /*length*/, StringTokenizer& tokens)
@@ -384,7 +383,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);
+ Log::debug("Sending to Broker: " + aMessage);
Util::writeFIFO(LOOLWSD::BrokerWritePipe, aMessage.c_str(), aMessage.length());
}
catch (const Poco::SyntaxException&)
@@ -613,10 +612,16 @@ void MasterProcessSession::dispatchChild()
if (!aUri.empty() && aUri.getScheme() == "file")
{
const std::string aJailDoc = jailDocumentURL.substr(1) + Path::separator() + std::to_string(childSession->_pidChild);
- Path aSrcFile(aUri.getPath());
- Path aDstFile(Path(getJailPath(childSession->_childId), aJailDoc), aSrcFile.getFileName());
- Path aDstPath(getJailPath(childSession->_childId), aJailDoc);
- Path aJailFile(aJailDoc, aSrcFile.getFileName());
+ const Path aSrcFile(aUri.getPath());
+ const Path aDstPath(getJailPath(childSession->_childId), aJailDoc);
+ const Path aDstFile(aDstPath, aSrcFile.getFileName());
+ const Path aJailFile(aJailDoc, aSrcFile.getFileName());
+
+ Log::debug("JailDoc: " + aJailDoc);
+ Log::debug("SrcFile: " + aSrcFile.toString());
+ Log::debug("DstPath: " + aDstPath.toString());
+ Log::debug("DstFile: " + aDstFile.toString());
+ Log::debug("JailFile: " + aJailFile.toString());
try
{
diff --git a/loolwsd/MasterProcessSession.hpp b/loolwsd/MasterProcessSession.hpp
index 0d6e3b7..85a66fe 100644
--- a/loolwsd/MasterProcessSession.hpp
+++ b/loolwsd/MasterProcessSession.hpp
@@ -26,8 +26,6 @@ public:
bool haveSeparateProcess();
- static Poco::Path getJailPath(Poco::UInt64 childId);
-
static std::map<Poco::Process::PID, Poco::UInt64> _childProcesses;
virtual bool getStatus(const char *buffer, int length);
@@ -73,11 +71,14 @@ public:
private:
+ static
+ Poco::Path getJailPath(const std::string& childId);
+
virtual bool _handleInput(const char *buffer, int length) override;
private:
// The id of the child process
- Poco::UInt64 _childId;
+ std::string _childId;
// The pid of the child process
Poco::Process::PID _pidChild;
int _curPart;
More information about the Libreoffice-commits
mailing list