[Libreoffice-commits] online.git: loolwsd/LOOLBroker.cpp loolwsd/LOOLKit.cpp loolwsd/LOOLWSD.cpp loolwsd/LOOLWSD.hpp
Henry Castro
hcastro at collabora.com
Sat Feb 13 17:23:11 UTC 2016
loolwsd/LOOLBroker.cpp | 43 +++++++++++++++++++++++--------------------
loolwsd/LOOLKit.cpp | 9 ++++++---
loolwsd/LOOLWSD.cpp | 23 +++++++++++++++++------
loolwsd/LOOLWSD.hpp | 3 ++-
4 files changed, 48 insertions(+), 30 deletions(-)
New commits:
commit 75b552bf71cd50cb6940e6d346e3f3ea2c48bb82
Author: Henry Castro <hcastro at collabora.com>
Date: Sat Feb 13 13:22:15 2016 -0400
loolwsd: create named pipes workspace
diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp
index 0b3ab32..9e48603 100644
--- a/loolwsd/LOOLBroker.cpp
+++ b/loolwsd/LOOLBroker.cpp
@@ -27,10 +27,9 @@ typedef int (LokHookPreInit) ( const char *install_path, const char *user_profi
using Poco::ProcessHandle;
-const std::string FIFO_FILE = "/tmp/loolwsdfifo";
-const std::string FIFO_BROKER = "/tmp/loolbroker.fifo";
+const std::string FIFO_LOOLWSD = "loolwsdfifo";
const std::string BROKER_SUFIX = ".fifo";
-const std::string BROKER_PREFIX = "/tmp/lokit";
+const std::string BROKER_PREFIX = "lokit";
static int readerChild = -1;
static int readerBroker = -1;
@@ -368,7 +367,7 @@ public:
{
if (poll(&aPoll, 1, POLL_TIMEOUT_MS) < 0)
{
- Log::error("Failed to poll pipe [" + FIFO_FILE + "].");
+ Log::error("Failed to poll pipe [" + FIFO_LOOLWSD + "].");
continue;
}
else
@@ -378,7 +377,7 @@ public:
if (nBytes < 0)
{
pStart = pEnd = nullptr;
- Log::error("Error reading message from pipe [" + FIFO_FILE + "].");
+ Log::error("Error reading message from pipe [" + FIFO_LOOLWSD + "].");
continue;
}
pStart = aBuffer;
@@ -387,7 +386,7 @@ public:
else
if (aPoll.revents & (POLLERR | POLLHUP))
{
- Log::error("Broken pipe [" + FIFO_FILE + "] with wsd.");
+ Log::error("Broken pipe [" + FIFO_LOOLWSD + "] with wsd.");
break;
}
}
@@ -472,12 +471,13 @@ static int createLibreOfficeKit(const bool sharePages,
int nFIFOWriter = -1;
int nFlags = O_WRONLY | O_NONBLOCK;
- const std::string pipe = BROKER_PREFIX + std::to_string(childCounter++) + BROKER_SUFIX;
+ 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 (!File(pipe).exists() && mkfifo(pipe.c_str(), 0666) < 0)
+ if (mkfifo(pipeKit.c_str(), 0666) < 0)
{
- Log::error("Error: Failed to create pipe FIFO [" + pipe + "].");
+ Log::error("Error: Failed to create pipe FIFO [" + pipeKit + "].");
return -1;
}
@@ -489,7 +489,7 @@ static int createLibreOfficeKit(const bool sharePages,
if (!(pid = fork()))
{
// child
- lokit_main(childRoot, sysTemplate, loTemplate, loSubPath, jailId, pipe);
+ lokit_main(childRoot, sysTemplate, loTemplate, loSubPath, jailId, pipeKit);
_exit(Application::EXIT_OK);
}
else
@@ -507,7 +507,7 @@ static int createLibreOfficeKit(const bool sharePages,
args.push_back("--lotemplate=" + loTemplate);
args.push_back("--losubpath=" + loSubPath);
args.push_back("--jailid=" + jailId);
- args.push_back("--pipe=" + pipe);
+ args.push_back("--pipe=" + pipeKit);
args.push_back("--clientport=" + std::to_string(ClientPortNumber));
Log::info("Launching LibreOfficeKit #" + std::to_string(childCounter) +
@@ -539,9 +539,9 @@ static int createLibreOfficeKit(const bool sharePages,
aFIFOCV.wait_for(
lock,
std::chrono::microseconds(80000),
- [&nFIFOWriter, &pipe, nFlags]
+ [&nFIFOWriter, &pipeKit, nFlags]
{
- return (nFIFOWriter = open(pipe.c_str(), nFlags)) >= 0;
+ return (nFIFOWriter = open(pipeKit.c_str(), nFlags)) >= 0;
});
if (nFIFOWriter < 0)
@@ -555,14 +555,14 @@ static int createLibreOfficeKit(const bool sharePages,
if (nFIFOWriter < 0)
{
- Log::error("Error: failed to open write pipe [" + pipe + "] with kit. Abandoning child.");
+ Log::error("Error: failed to open write pipe [" + pipeKit + "] with kit. Abandoning child.");
ChildProcess(childPID, -1, -1);
return -1;
}
if ((nFlags = fcntl(nFIFOWriter, F_GETFL, 0)) < 0)
{
- Log::error("Error: failed to get pipe flags [" + pipe + "].");
+ Log::error("Error: failed to get pipe flags [" + pipeKit + "].");
ChildProcess(childPID, -1, -1);
return -1;
}
@@ -570,7 +570,7 @@ static int createLibreOfficeKit(const bool sharePages,
nFlags &= ~O_NONBLOCK;
if (fcntl(nFIFOWriter, F_SETFL, nFlags) < 0)
{
- Log::error("Error: failed to set pipe flags [" + pipe + "].");
+ Log::error("Error: failed to set pipe flags [" + pipeKit + "].");
ChildProcess(childPID, -1, -1);
return -1;
}
@@ -696,9 +696,11 @@ int main(int argc, char** argv)
exit(Application::EXIT_SOFTWARE);
}
- if ( (readerBroker = open(FIFO_FILE.c_str(), O_RDONLY) ) < 0 )
+ const Path pipePath = Path::forDirectory(childRoot + Path::separator() + FIFO_PATH);
+ const std::string pipeLoolwsd = Path(pipePath, FIFO_LOOLWSD).toString();
+ if ( (readerBroker = open(pipeLoolwsd.c_str(), O_RDONLY) ) < 0 )
{
- Log::error("Error: failed to open pipe [" + FIFO_FILE + "] read only. Exiting.");
+ Log::error("Error: failed to open pipe [" + pipeLoolwsd + "] read only. Exiting.");
exit(Application::EXIT_SOFTWARE);
}
@@ -721,13 +723,14 @@ int main(int argc, char** argv)
}
int nFlags = O_RDONLY | O_NONBLOCK;
- if (!File(FIFO_BROKER).exists() && mkfifo(FIFO_BROKER.c_str(), 0666) == -1)
+ const std::string pipeBroker = Path(pipePath, FIFO_BROKER).toString();
+ if (mkfifo(pipeBroker.c_str(), 0666) == -1)
{
Log::error("Error: Failed to create pipe FIFO [" + FIFO_BROKER + "].");
exit(Application::EXIT_SOFTWARE);
}
- if ((readerChild = open(FIFO_BROKER.c_str(), nFlags) ) < 0)
+ if ((readerChild = open(pipeBroker.c_str(), nFlags) ) < 0)
{
Log::error("Error: pipe opened for reading.");
exit(Application::EXIT_SOFTWARE);
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index eb2c2ab..61f5667 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -70,7 +70,8 @@ using Poco::Path;
using Poco::ThreadLocal;
const std::string CHILD_URI = "/loolws/child/";
-const std::string LOKIT_BROKER = "/tmp/loolbroker.fifo";
+const std::string FIFO_PATH = "pipe";
+const std::string FIFO_BROKER = "loolbroker.fifo";
namespace
{
@@ -640,9 +641,11 @@ void lokit_main(const std::string& childRoot,
exit(Application::EXIT_SOFTWARE);
}
- if ( (writerBroker = open(LOKIT_BROKER.c_str(), O_WRONLY) ) < 0 )
+ const Path pipePath = Path::forDirectory(childRoot + Path::separator() + FIFO_PATH);
+ const std::string pipeBroker = Path(pipePath, FIFO_BROKER).toString();
+ if ( (writerBroker = open(pipeBroker.c_str(), O_WRONLY) ) < 0 )
{
- Log::error("Error: failed to open pipe [" + LOKIT_BROKER + "] write only.");
+ Log::error("Error: failed to open pipe [" + FIFO_BROKER + "] write only.");
exit(Application::EXIT_SOFTWARE);
}
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index ffa047f..9b69e57 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -729,8 +729,8 @@ int LOOLWSD::NumPreSpawnedChildren = 10;
bool LOOLWSD::DoTest = false;
const std::string LOOLWSD::CHILD_URI = "/loolws/child/";
const std::string LOOLWSD::PIDLOG = "/tmp/loolwsd.pid";
-const std::string LOOLWSD::LOKIT_PIDLOG = "/tmp/lokit.pid";
-const std::string LOOLWSD::FIFO_FILE = "/tmp/loolwsdfifo";
+const std::string LOOLWSD::FIFO_PATH = "pipe";
+const std::string LOOLWSD::FIFO_LOOLWSD = "loolwsdfifo";
LOOLWSD::LOOLWSD()
{
@@ -931,9 +931,17 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
filePID << Process::id();
}
- if (!File(FIFO_FILE).exists() && mkfifo(FIFO_FILE.c_str(), 0666) == -1)
+ const Path pipePath = Path::forDirectory(ChildRoot + Path::separator() + FIFO_PATH);
+ if (!File(pipePath).createDirectory())
{
- Log::error("Error: Failed to create pipe FIFO [" + FIFO_FILE + "].");
+ Log::error("Error: Failed to create pipe directory [" + pipePath.toString() + "].");
+ return Application::EXIT_SOFTWARE;
+ }
+
+ const std::string pipeLoolwsd = Path(pipePath, FIFO_LOOLWSD).toString();
+ if (mkfifo(pipeLoolwsd.c_str(), 0666) == -1)
+ {
+ Log::error("Error: Failed to create pipe FIFO [" + pipeLoolwsd + "].");
return Application::EXIT_SOFTWARE;
}
@@ -979,9 +987,9 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
srv2.start();
- if ( (BrokerWritePipe = open(FIFO_FILE.c_str(), O_WRONLY) ) < 0 )
+ if ( (BrokerWritePipe = open(pipeLoolwsd.c_str(), O_WRONLY) ) < 0 )
{
- Log::error("Error: failed to open pipe [" + FIFO_FILE + "] write only.");
+ Log::error("Error: failed to open pipe [" + pipeLoolwsd + "] write only.");
return Application::EXIT_SOFTWARE;
}
@@ -1095,6 +1103,9 @@ 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/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp
index e145288..bcddcbb 100644
--- a/loolwsd/LOOLWSD.hpp
+++ b/loolwsd/LOOLWSD.hpp
@@ -163,7 +163,8 @@ public:
static const std::string CHILD_URI;
static const std::string PIDLOG;
- static const std::string FIFO_FILE;
+ static const std::string FIFO_PATH;
+ static const std::string FIFO_LOOLWSD;
static const std::string LOKIT_PIDLOG;
static
More information about the Libreoffice-commits
mailing list