[Libreoffice-commits] online.git: loolwsd/LOOLBroker.cpp loolwsd/LOOLKit.cpp loolwsd/LOOLWSD.cpp loolwsd/MasterProcessSession.cpp loolwsd/MasterProcessSession.hpp
Henry Castro
hcastro at collabora.com
Sat Feb 13 23:02:43 UTC 2016
loolwsd/LOOLBroker.cpp | 4 +---
loolwsd/LOOLKit.cpp | 23 +++++------------------
loolwsd/LOOLWSD.cpp | 3 ---
loolwsd/MasterProcessSession.cpp | 23 +++++++++--------------
loolwsd/MasterProcessSession.hpp | 4 +---
5 files changed, 16 insertions(+), 41 deletions(-)
New commits:
commit 72db8ed63a73830f3413523ca504b1ca767f7c9c
Author: Henry Castro <hcastro at collabora.com>
Date: Sat Feb 13 18:58:28 2016 -0400
loolwsd: replace the random jail id for lokit process id
diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp
index 9e48603..bd35210 100644
--- a/loolwsd/LOOLBroker.cpp
+++ b/loolwsd/LOOLBroker.cpp
@@ -473,7 +473,6 @@ static int createLibreOfficeKit(const bool sharePages,
const Path pipePath = Path::forDirectory(childRoot + Path::separator() + FIFO_PATH);
const std::string pipeKit = Path(pipePath, BROKER_PREFIX + std::to_string(childCounter++) + BROKER_SUFIX).toString();
- const std::string jailId = Util::createRandomDir(childRoot);
if (mkfifo(pipeKit.c_str(), 0666) < 0)
{
@@ -489,7 +488,7 @@ static int createLibreOfficeKit(const bool sharePages,
if (!(pid = fork()))
{
// child
- lokit_main(childRoot, sysTemplate, loTemplate, loSubPath, jailId, pipeKit);
+ lokit_main(childRoot, sysTemplate, loTemplate, loSubPath, pipeKit);
_exit(Application::EXIT_OK);
}
else
@@ -506,7 +505,6 @@ static int createLibreOfficeKit(const bool sharePages,
args.push_back("--systemplate=" + sysTemplate);
args.push_back("--lotemplate=" + loTemplate);
args.push_back("--losubpath=" + loSubPath);
- args.push_back("--jailid=" + jailId);
args.push_back("--pipe=" + pipeKit);
args.push_back("--clientport=" + std::to_string(ClientPortNumber));
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index 61f5667..5655a8c 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -400,9 +400,8 @@ public:
auto session = std::make_shared<ChildProcessSession>(sessionId, ws, _loKit, _loKitDocument, _jailId,
[this](const std::string& id, const std::string& uri) { return onLoad(id, uri); },
[this](const std::string& id) { onUnload(id); });
- // child Jail TID PID
- std::string hello("child " + _jailId + " " +
- sessionId + " " + std::to_string(Process::id()));
+ // child -> 0, sessionId -> 1, PID -> 2
+ std::string hello("child " + sessionId + " " + std::to_string(Process::id()));
session->sendTextFrame(hello);
auto thread = std::make_shared<Connection>(session, ws);
@@ -590,7 +589,6 @@ void lokit_main(const std::string& childRoot,
const std::string& sysTemplate,
const std::string& loTemplate,
const std::string& loSubPath,
- const std::string& jailId,
const std::string& pipe)
{
#ifdef LOOLKIT_NO_MAIN
@@ -607,13 +605,14 @@ void lokit_main(const std::string& childRoot,
assert(!childRoot.empty());
assert(!sysTemplate.empty());
assert(!loTemplate.empty());
- assert(!jailId.empty());
assert(!loSubPath.empty());
assert(!pipe.empty());
std::map<std::string, std::shared_ptr<Document>> _documents;
+ static const std::string jailId = std::to_string(Process::id());
static const std::string process_name = "loolkit";
+
#ifdef __linux
if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(process_name.c_str()), 0, 0, 0) != 0)
Log::error("Cannot set process name to " + process_name + ".");
@@ -898,12 +897,6 @@ int main(int argc, char** argv)
if (*eq)
loSubPath = std::string(++eq);
}
- else if (strstr(cmd, "--jailid=") == cmd)
- {
- eq = strchrnul(cmd, '=');
- if (*eq)
- jailId = std::string(++eq);
- }
else if (strstr(cmd, "--pipe=") == cmd)
{
eq = strchrnul(cmd, '=');
@@ -924,12 +917,6 @@ int main(int argc, char** argv)
exit(Application::EXIT_SOFTWARE);
}
- if (jailId.empty())
- {
- Log::error("Error: --jailid is empty");
- exit(Application::EXIT_SOFTWARE);
- }
-
if ( pipe.empty() )
{
Log::error("Error: --pipe is empty");
@@ -954,7 +941,7 @@ int main(int argc, char** argv)
Log::warn("Note: LOK_VIEW_CALLBACK is not set.");
}
- lokit_main(childRoot, sysTemplate, loTemplate, loSubPath, jailId, pipe);
+ lokit_main(childRoot, sysTemplate, loTemplate, loSubPath, pipe);
return Application::EXIT_OK;
}
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 9b69e57..f2d41b7 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -1103,9 +1103,6 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
Util::removeFile(path, true);
}
- Log::debug("Cleaning up pipe directory [" + pipePath.toString() + "].");
- Util::removeFile(pipePath, true);
-
Log::info("Process [loolwsd] finished.");
return Application::EXIT_OK;
}
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index 91bfb89..b7b4275 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -39,7 +39,6 @@ MasterProcessSession::MasterProcessSession(const std::string& id,
const Kind kind,
std::shared_ptr<Poco::Net::WebSocket> ws) :
LOOLSession(id, kind, ws),
- _pidChild(0),
_curPart(0),
_loadPart(-1)
{
@@ -148,7 +147,7 @@ bool MasterProcessSession::_handleInput(const char *buffer, int length)
if (url.find(filePrefix) == 0)
{
// Rewrite file:// URLs, as they are visible to the outside world.
- Path path(MasterProcessSession::getJailPath(_jailId), url.substr(filePrefix.length()));
+ Path path(MasterProcessSession::getJailPath(_childId), url.substr(filePrefix.length()));
url = filePrefix + path.toString().substr(1);
}
peer->_saveAsQueue.put(url);
@@ -245,24 +244,22 @@ bool MasterProcessSession::_handleInput(const char *buffer, int length)
sendTextFrame("error: cmd=child kind=invalid");
return false;
}
- if (tokens.count() != 4)
+ if (tokens.count() != 3)
{
sendTextFrame("error: cmd=child kind=syntax");
return false;
}
- const auto jailId = tokens[1];
- setId(tokens[2]);
- const Process::PID pidChild = std::stoull(tokens[3]);
+ // child -> 0, sessionId -> 1, PID -> 2
+ setId(tokens[1]);
+ _childId = tokens[2];
std::unique_lock<std::mutex> lock(AvailableChildSessionMutex);
AvailableChildSessions.emplace(getId(), shared_from_this());
- Log::info() << getName() << " mapped " << this << " jailId=" << jailId << ", id=" << getId()
+ Log::info() << getName() << " mapped " << this << " jailId=" << _childId << ", id=" << getId()
<< " into _availableChildSessions, size=" << AvailableChildSessions.size() << Log::end;
- _jailId = jailId;
- _pidChild = pidChild;
lock.unlock();
AvailableChildSessionCV.notify_one();
}
@@ -384,7 +381,7 @@ bool MasterProcessSession::_handleInput(const char *buffer, int length)
bool MasterProcessSession::haveSeparateProcess()
{
- return !_jailId.empty();
+ return !_childId.empty();
}
Poco::Path MasterProcessSession::getJailPath(const std::string& childId)
@@ -766,10 +763,8 @@ void MasterProcessSession::dispatchChild()
return;
}
- const auto jailRoot = Poco::Path(LOOLWSD::ChildRoot, childSession->_jailId);
- const auto childId = std::to_string(childSession->_pidChild);
-
- auto document = DocumentURI::create(_docURL, jailRoot.toString(), childId);
+ const auto jailRoot = Poco::Path(LOOLWSD::ChildRoot, childSession->_childId);
+ auto document = DocumentURI::create(_docURL, jailRoot.toString(), childSession->_childId);
_peer = childSession;
childSession->_peer = shared_from_this();
diff --git a/loolwsd/MasterProcessSession.hpp b/loolwsd/MasterProcessSession.hpp
index 901b523..68c82d2 100644
--- a/loolwsd/MasterProcessSession.hpp
+++ b/loolwsd/MasterProcessSession.hpp
@@ -80,10 +80,8 @@ private:
virtual bool _handleInput(const char *buffer, int length) override;
private:
- // The jail id of the child process
- std::string _jailId;
// The pid of the child process
- Poco::Process::PID _pidChild;
+ std::string _childId;
int _curPart;
int _loadPart;
/// Kind::ToClient instances store URLs of completed 'save as' documents.
More information about the Libreoffice-commits
mailing list