loolwsd: childId is now string
Change-Id: I7037c03d2b40ff88deed0619e8a34ce5434913a3 Reviewed-on: https://gerrit.libreoffice.org/21095 Reviewed-by: Ashod Nakashian <ashnakash@gmail.com> Tested-by: Ashod Nakashian <ashnakash@gmail.com>
This commit is contained in:
parent
53bff1f1ca
commit
75c65af930
4 changed files with 27 additions and 19 deletions
|
@ -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());
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue