[Libreoffice-commits] online.git: 2 commits - loolwsd/ChildProcessSession.cpp loolwsd/LOOLKit.cpp loolwsd/loolmap.c loolwsd/LOOLWSD.cpp loolwsd/LOOLWSD.hpp
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Wed Dec 23 09:23:57 PST 2015
loolwsd/ChildProcessSession.cpp | 109 -----------
loolwsd/LOOLKit.cpp | 82 ++++++--
loolwsd/LOOLWSD.cpp | 379 ----------------------------------------
loolwsd/LOOLWSD.hpp | 1
loolwsd/loolmap.c | 27 +-
5 files changed, 78 insertions(+), 520 deletions(-)
New commits:
commit 37c7f2f32575e7c660796e041b203d64748d3c28
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Wed Dec 23 09:56:46 2015 -0500
loolwsd: fixes to loolmap
Change-Id: I58ce3dbbd6bbd1e3eb860ba6c3044ba4a61e281d
Reviewed-on: https://gerrit.libreoffice.org/20909
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/loolwsd/loolmap.c b/loolwsd/loolmap.c
index 08b149a..21792b9 100644
--- a/loolwsd/loolmap.c
+++ b/loolwsd/loolmap.c
@@ -1,6 +1,7 @@
#include <string.h>
#include <ctype.h>
#include <errno.h>
+#include <error.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
@@ -120,15 +121,15 @@ static void total_smaps(unsigned proc_id, const char *file, const char *cmdline)
error(EXIT_FAILURE, errno, "%s\n", cmdline);
printf("%s\n", cmdline);
- printf("Process ID :%20ld\n", proc_id);
+ printf("Process ID :%20d\n", proc_id);
printf("--------------------------------------\n");
- printf("Shared Clean :%20ld kB\n", total_shared_clean);
- printf("Shared Dirty :%20ld kB\n", total_shared_dirty);
- printf("Private Clean :%20ld kB\n", total_private_clean);
- printf("Private Dirty :%20ld kB\n", total_private_dirty);
+ printf("Shared Clean :%20lld kB\n", total_shared_clean);
+ printf("Shared Dirty :%20lld kB\n", total_shared_dirty);
+ printf("Private Clean :%20lld kB\n", total_private_clean);
+ printf("Private Dirty :%20lld kB\n", total_private_dirty);
printf("--------------------------------------\n");
- printf("Shared :%20ld kB\n", total_shared_clean + total_shared_dirty);
- printf("Private :%20ld kB\n\n", total_private_clean + total_private_dirty);
+ printf("Shared :%20lld kB\n", total_shared_clean + total_shared_dirty);
+ printf("Private :%20lld kB\n\n", total_private_clean + total_private_dirty);
}
int main(int argc, char **argv)
@@ -145,7 +146,7 @@ int main(int argc, char **argv)
getopt(argc, argv, "");
if (argc != 2)
- error(EXIT_FAILURE, EINVAL);
+ error(EXIT_FAILURE, EINVAL, "incorrect arguments");
root_proc = opendir("/proc");
if (!root_proc)
@@ -154,7 +155,7 @@ int main(int argc, char **argv)
while ( ( dir_proc = readdir(root_proc) ) )
{
if ( !dir_proc && !dir_proc->d_name )
- error(EXIT_FAILURE, ENOTDIR );
+ error(EXIT_FAILURE, ENOTDIR, "bad dir");
if ( *dir_proc->d_name > '0' && *dir_proc->d_name <= '9' )
{
@@ -165,13 +166,15 @@ int main(int argc, char **argv)
!strstr(cmdline, argv[0]) )
{
snprintf(path_proc, sizeof(path_proc), "/proc/%s/%s", dir_proc->d_name, "smaps");
- total_smaps(pid_proc, path_proc, cmdline);
- }
+ total_smaps(pid_proc, path_proc, cmdline);
+ }
}
}
if ( errno )
- error(EXIT_FAILURE, errno);
+ error(EXIT_FAILURE, errno, "fail");
return EXIT_SUCCESS;
}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 9d7fbec138f8e35e4a4f68877721326539066f0d
Author: Henry Castro <hcastro at collabora.com>
Date: Mon Dec 21 09:54:52 2015 -0500
loolwsd: Merged improved lifecycle prototype
Enabled the broker and kit processes.
Change-Id: I9afedbccac35732ffe846494cae8135d306e6311
Reviewed-on: https://gerrit.libreoffice.org/20907
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 dd56da0..cf75086 100644
--- a/loolwsd/ChildProcessSession.cpp
+++ b/loolwsd/ChildProcessSession.cpp
@@ -211,114 +211,15 @@ extern "C"
{
static void myCallback(int nType, const char* pPayload, void* pData)
{
- ChildProcessSession *srv = reinterpret_cast<ChildProcessSession *>(pData);
+ /*pid_t tid = syscall(SYS_gettid);
+ std::cout << tid << " callbackWorker : " << priv->m_nViewId << " " << std::string(callbackTypeToString(nType)) << " " << std::string(pPayload ? pPayload : "(nil)") << std::endl;*/
- switch ((LibreOfficeKitCallbackType) nType)
- {
- case LOK_CALLBACK_INVALIDATE_TILES:
- {
- int curPart = srv->_loKitDocument->pClass->getPart(srv->_loKitDocument);
- srv->sendTextFrame("curpart: part=" + std::to_string(curPart));
- if (srv->_docType == "text")
- {
- curPart = 0;
- }
- StringTokenizer tokens(std::string(pPayload), " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
- if (tokens.count() == 4)
- {
- int x, y, width, height;
-
- try {
- x = std::stoi(tokens[0]);
- y = std::stoi(tokens[1]);
- width = std::stoi(tokens[2]);
- height = std::stoi(tokens[3]);
- }
- catch (std::out_of_range&)
- {
- // something went wrong, invalidate everything
- Application::instance().logger().information(Util::logPrefix() + "Ignoring integer values out of range: " + pPayload);
- x = 0;
- y = 0;
- width = INT_MAX;
- height = INT_MAX;
- }
-
- srv->sendTextFrame("invalidatetiles:"
- " part=" + std::to_string(curPart) +
- " x=" + std::to_string(x) +
- " y=" + std::to_string(y) +
- " width=" + std::to_string(width) +
- " height=" + std::to_string(height));
- }
- else
- {
- srv->sendTextFrame("invalidatetiles: " + std::string(pPayload));
- }
- }
- break;
- case LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR:
- srv->sendTextFrame("invalidatecursor: " + std::string(pPayload));
- break;
- case LOK_CALLBACK_TEXT_SELECTION:
- srv->sendTextFrame("textselection: " + std::string(pPayload));
- break;
- case LOK_CALLBACK_TEXT_SELECTION_START:
- srv->sendTextFrame("textselectionstart: " + std::string(pPayload));
- break;
- case LOK_CALLBACK_TEXT_SELECTION_END:
- srv->sendTextFrame("textselectionend: " + std::string(pPayload));
- break;
- case LOK_CALLBACK_CURSOR_VISIBLE:
- srv->sendTextFrame("cursorvisible: " + std::string(pPayload));
- break;
- case LOK_CALLBACK_GRAPHIC_SELECTION:
- srv->sendTextFrame("graphicselection: " + std::string(pPayload));
- break;
- case LOK_CALLBACK_CELL_CURSOR:
- srv->sendTextFrame("cellcursor: " + std::string(pPayload));
- break;
- case LOK_CALLBACK_CELL_FORMULA:
- srv->sendTextFrame("cellformula: " + std::string(pPayload));
- break;
- case LOK_CALLBACK_MOUSE_POINTER:
- srv->sendTextFrame("mousepointer: " + std::string(pPayload));
- break;
- case LOK_CALLBACK_HYPERLINK_CLICKED:
- srv->sendTextFrame("hyperlinkclicked: " + std::string(pPayload));
- break;
- case LOK_CALLBACK_STATE_CHANGED:
- srv->sendTextFrame("statechanged: " + std::string(pPayload));
- break;
- case LOK_CALLBACK_STATUS_INDICATOR_START:
- srv->sendTextFrame("statusindicatorstart:");
- break;
- case LOK_CALLBACK_STATUS_INDICATOR_SET_VALUE:
- srv->sendTextFrame("statusindicatorsetvalue: " + std::string(pPayload));
- break;
- case LOK_CALLBACK_STATUS_INDICATOR_FINISH:
- srv->sendTextFrame("statusindicatorfinish:");
- break;
- case LOK_CALLBACK_SEARCH_NOT_FOUND:
- srv->sendTextFrame("searchnotfound: " + std::string(pPayload));
- break;
- case LOK_CALLBACK_SEARCH_RESULT_SELECTION:
- srv->sendTextFrame("searchresultselection: " + std::string(pPayload));
- break;
- case LOK_CALLBACK_DOCUMENT_SIZE_CHANGED:
- srv->getStatus("", 0);
- srv->getPartPageRectangles("", 0);
- break;
- case LOK_CALLBACK_SET_PART:
- srv->sendTextFrame("setpart: " + std::string(pPayload));
- break;
- case LOK_CALLBACK_UNO_COMMAND_RESULT:
- srv->sendTextFrame("unocommandresult: " + std::string(pPayload));
- break;
- }
+ ChildProcessSession::_callbackQueue.enqueueNotification(new CallBackNotification(nType, pPayload ? pPayload : "(nil)", pData));
+ //std::string aPayLoad(pPayload ? pPayload : "(nil)");
}
}
+
bool ChildProcessSession::loadDocument(const char *buffer, int length, StringTokenizer& tokens)
{
int part = -1;
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index f20a8dd..3c6917a 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -109,25 +109,38 @@ public:
void callback(int nType, std::string& rPayload, void* pData)
{
ChildProcessSession *srv = reinterpret_cast<ChildProcessSession *>(pData);
- pid_t tid = syscall(SYS_gettid);
- //if ( nType == LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR )
- std::cout << tid << " callback : " << srv->_viewId << " " << callbackTypeToString(nType) << " " << rPayload << std::endl;
-
- switch ( nType )
+ switch ((LibreOfficeKitCallbackType) nType)
{
case LOK_CALLBACK_INVALIDATE_TILES:
{
- //int curPart = srv->_loKitDocument->pClass->getPart(srv->_loKitDocument);
- int curPart = 0;
+ int curPart = srv->_loKitDocument->pClass->getPart(srv->_loKitDocument);
srv->sendTextFrame("curpart: part=" + std::to_string(curPart));
+ if (srv->_docType == "text")
+ {
+ curPart = 0;
+ }
StringTokenizer tokens(rPayload, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
if (tokens.count() == 4)
{
- int x(std::stoi(tokens[0]));
- int y(std::stoi(tokens[1]));
- int width(std::stoi(tokens[2]));
- int height(std::stoi(tokens[3]));
+ int x, y, width, height;
+
+ try {
+ x = std::stoi(tokens[0]);
+ y = std::stoi(tokens[1]);
+ width = std::stoi(tokens[2]);
+ height = std::stoi(tokens[3]);
+ }
+ catch (std::out_of_range&)
+ {
+ // something went wrong, invalidate everything
+ std::cout << Util::logPrefix() << "Ignoring integer values out of range: " << rPayload << std::endl;
+ x = 0;
+ y = 0;
+ width = INT_MAX;
+ height = INT_MAX;
+ }
+
srv->sendTextFrame("invalidatetiles:"
" part=" + std::to_string(curPart) +
" x=" + std::to_string(x) +
@@ -135,22 +148,12 @@ public:
" width=" + std::to_string(width) +
" height=" + std::to_string(height));
}
- else {
+ else
+ {
srv->sendTextFrame("invalidatetiles: " + rPayload);
}
}
break;
- case LOK_CALLBACK_STATUS_INDICATOR_START:
- srv->sendTextFrame("statusindicatorstart:");
- break;
-
- case LOK_CALLBACK_STATUS_INDICATOR_SET_VALUE:
- srv->sendTextFrame("statusindicatorsetvalue: " + rPayload);
- break;
-
- case LOK_CALLBACK_STATUS_INDICATOR_FINISH:
- srv->sendTextFrame("statusindicatorfinish:");
- break;
case LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR:
srv->sendTextFrame("invalidatecursor: " + rPayload);
break;
@@ -169,25 +172,49 @@ public:
case LOK_CALLBACK_GRAPHIC_SELECTION:
srv->sendTextFrame("graphicselection: " + rPayload);
break;
+ case LOK_CALLBACK_CELL_CURSOR:
+ srv->sendTextFrame("cellcursor: " + rPayload);
+ break;
+ case LOK_CALLBACK_CELL_FORMULA:
+ srv->sendTextFrame("cellformula: " + rPayload);
+ break;
+ case LOK_CALLBACK_MOUSE_POINTER:
+ srv->sendTextFrame("mousepointer: " + rPayload);
+ break;
case LOK_CALLBACK_HYPERLINK_CLICKED:
srv->sendTextFrame("hyperlinkclicked: " + rPayload);
break;
case LOK_CALLBACK_STATE_CHANGED:
srv->sendTextFrame("statechanged: " + rPayload);
break;
+ case LOK_CALLBACK_STATUS_INDICATOR_START:
+ srv->sendTextFrame("statusindicatorstart:");
+ break;
+ case LOK_CALLBACK_STATUS_INDICATOR_SET_VALUE:
+ srv->sendTextFrame("statusindicatorsetvalue: " + rPayload);
+ break;
+ case LOK_CALLBACK_STATUS_INDICATOR_FINISH:
+ srv->sendTextFrame("statusindicatorfinish:");
+ break;
case LOK_CALLBACK_SEARCH_NOT_FOUND:
srv->sendTextFrame("searchnotfound: " + rPayload);
break;
+ case LOK_CALLBACK_SEARCH_RESULT_SELECTION:
+ srv->sendTextFrame("searchresultselection: " + rPayload);
+ break;
case LOK_CALLBACK_DOCUMENT_SIZE_CHANGED:
srv->getStatus("", 0);
+ srv->getPartPageRectangles("", 0);
break;
case LOK_CALLBACK_SET_PART:
srv->sendTextFrame("setpart: " + rPayload);
break;
+ case LOK_CALLBACK_UNO_COMMAND_RESULT:
+ srv->sendTextFrame("unocommandresult: " + rPayload);
+ break;
}
}
-
void run()
{
while ( true )
@@ -390,6 +417,13 @@ void run_lok_main(const std::string &loSubPath, Poco::UInt64 _childId, const std
std::cout << Util::logPrefix() << "Cannot set thread name :" << strerror(errno) << std::endl;
#endif
+ if (std::getenv("SLEEPFORDEBUGGER"))
+ {
+ std::cout << "Sleeping " << std::getenv("SLEEPFORDEBUGGER") << " seconds, attach process "
+ << Process::id() << " in debugger now." << std::endl;
+ Thread::sleep(std::stoul(std::getenv("SLEEPFORDEBUGGER")) * 1000);
+ }
+
try
{
#ifdef __APPLE__
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 2bb61a1..d543c32 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -153,91 +153,6 @@ using Poco::URI;
namespace
{
- ThreadLocal<std::string> sourceForLinkOrCopy;
- ThreadLocal<Path> destinationForLinkOrCopy;
-
- int linkOrCopyFunction(const char *fpath,
- const struct stat* /*sb*/,
- int typeflag,
- struct FTW* /*ftwbuf*/)
- {
- if (strcmp(fpath, sourceForLinkOrCopy->c_str()) == 0)
- return 0;
-
- assert(fpath[strlen(sourceForLinkOrCopy->c_str())] == '/');
- const char *relativeOldPath = fpath + strlen(sourceForLinkOrCopy->c_str()) + 1;
-
-#ifdef __APPLE__
- if (strcmp(relativeOldPath, "PkgInfo") == 0)
- return 0;
-#endif
-
- Path newPath(*destinationForLinkOrCopy, Path(relativeOldPath));
-
- switch (typeflag)
- {
- case FTW_F:
- File(newPath.parent()).createDirectories();
- if (link(fpath, newPath.toString().c_str()) == -1)
- {
- Application::instance().logger().error(Util::logPrefix() +
- "link(\"" + fpath + "\",\"" + newPath.toString() + "\") failed: " +
- strerror(errno));
- exit(1);
- }
- break;
- case FTW_DP:
- {
- struct stat st;
- if (stat(fpath, &st) == -1)
- {
- Application::instance().logger().error(Util::logPrefix() +
- "stat(\"" + fpath + "\") failed: " +
- strerror(errno));
- return 1;
- }
- File(newPath).createDirectories();
- struct utimbuf ut;
- ut.actime = st.st_atime;
- ut.modtime = st.st_mtime;
- if (utime(newPath.toString().c_str(), &ut) == -1)
- {
- Application::instance().logger().error(Util::logPrefix() +
- "utime(\"" + newPath.toString() + "\", &ut) failed: " +
- strerror(errno));
- return 1;
- }
- }
- break;
- case FTW_DNR:
- Application::instance().logger().error(Util::logPrefix() +
- "Cannot read directory '" + fpath + "'");
- return 1;
- case FTW_NS:
- Application::instance().logger().error(Util::logPrefix() +
- "nftw: stat failed for '" + fpath + "'");
- return 1;
- case FTW_SLN:
- Application::instance().logger().information(Util::logPrefix() +
- "nftw: symlink to nonexistent file: '" + fpath + "', ignored");
- break;
- default:
- assert(false);
- }
- return 0;
- }
-
- void linkOrCopy(const std::string& source, const Path& destination)
- {
- *sourceForLinkOrCopy = source;
- if (sourceForLinkOrCopy->back() == '/')
- sourceForLinkOrCopy->pop_back();
- *destinationForLinkOrCopy = destination;
- if (nftw(source.c_str(), linkOrCopyFunction, 10, FTW_DEPTH) == -1)
- Application::instance().logger().error(Util::logPrefix() +
- "linkOrCopy: nftw() failed for '" + source + "'");
- }
-
void dropCapability(
#ifdef __linux
cap_value_t capability
@@ -752,7 +667,6 @@ std::string LOOLWSD::childRoot;
std::string LOOLWSD::loSubPath = "lo";
std::string LOOLWSD::jail;
Poco::NamedMutex LOOLWSD::_namedMutexLOOL("loolwsd");
-Poco::SharedMemory LOOLWSD::_sharedForkChild("loolwsd", sizeof(bool), Poco::SharedMemory::AM_WRITE);
int LOOLWSD::_numPreSpawnedChildren = 10;
bool LOOLWSD::doTest = false;
@@ -916,299 +830,6 @@ void LOOLWSD::displayHelp()
helpFormatter.format(std::cout);
}
-// Writer, Impress or Calc
-void LOOLWSD::componentMain()
-{
-#ifdef __linux
- if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>("libreofficekit"), 0, 0, 0) != 0)
- std::cout << Util::logPrefix() << "Cannot set thread name :" << strerror(errno) << std::endl;
-
- setSignals(false);
-#endif
-
- try
- {
- _namedMutexLOOL.lock();
-
- Path jailPath = Path::forDirectory(LOOLWSD::childRoot + Path::separator() + std::to_string(_childId));
- File(jailPath).createDirectory();
-
- Path jailLOInstallation(jailPath, LOOLWSD::loSubPath);
- jailLOInstallation.makeDirectory();
- File(jailLOInstallation).createDirectory();
-
- // Copy (link) LO installation and other necessary files into it from the template
-
- linkOrCopy(LOOLWSD::sysTemplate, jailPath);
- linkOrCopy(LOOLWSD::loTemplate, jailLOInstallation);
-
- // 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)
- {
- File networkFile(*it);
- if (networkFile.exists())
- {
- networkFile.copyTo(Path(jailPath, "/etc").toString());
- }
- }
-#ifdef __linux
- // Create the urandom and random devices
- File(Path(jailPath, "/dev")).createDirectory();
- if (mknod((jailPath.toString() + "/dev/random").c_str(),
- S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH,
- makedev(1, 8)) != 0)
- {
- Application::instance().logger().error(Util::logPrefix() +
- "mknod(" + jailPath.toString() + "/dev/random) failed: " +
- strerror(errno));
-
- }
- if (mknod((jailPath.toString() + "/dev/urandom").c_str(),
- S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH,
- makedev(1, 9)) != 0)
- {
- Application::instance().logger().error(Util::logPrefix() +
- "mknod(" + jailPath.toString() + "/dev/urandom) failed: " +
- strerror(errno));
- }
-#endif
-
- Application::instance().logger().information("componentMain -> chroot(\"" + jailPath.toString() + "\")");
- if (chroot(jailPath.toString().c_str()) == -1)
- {
- logger().error("chroot(\"" + jailPath.toString() + "\") failed: " + strerror(errno));
- exit(Application::EXIT_UNAVAILABLE);
- }
-
- if (chdir("/") == -1)
- {
- logger().error(std::string("chdir(\"/\") in jail failed: ") + strerror(errno));
- exit(Application::EXIT_UNAVAILABLE);
- }
-
-#ifdef __linux
- dropCapability(CAP_SYS_CHROOT);
- dropCapability(CAP_MKNOD);
- dropCapability(CAP_FOWNER);
-#else
- dropCapability();
-#endif
-
- if (std::getenv("SLEEPFORDEBUGGER"))
- {
- std::cout << "Sleeping " << std::getenv("SLEEPFORDEBUGGER") << " seconds, " <<
- "attach process " << Process::id() << " in debugger now." << std::endl;
- Thread::sleep(std::stoul(std::getenv("SLEEPFORDEBUGGER")) * 1000);
- }
-
-#ifdef __APPLE__
- LibreOfficeKit *loKit(lok_init_2(("/" + loSubPath + "/Frameworks").c_str(), "file:///user"));
-#else
- LibreOfficeKit *loKit(lok_init_2(("/" + loSubPath + "/program").c_str(), "file:///user"));
-#endif
-
- if (!loKit)
- {
- logger().fatal(Util::logPrefix() + "LibreOfficeKit initialisation failed");
- exit(Application::EXIT_UNAVAILABLE);
- }
-
- _namedMutexLOOL.unlock();
-
- // Open websocket connection between the child process and the
- // parent. The parent forwards us requests that it can't handle.
-
- HTTPClientSession cs("127.0.0.1", MASTER_PORT_NUMBER);
- cs.setTimeout(0);
- HTTPRequest request(HTTPRequest::HTTP_GET, LOOLWSD::CHILD_URI);
- HTTPResponse response;
- std::shared_ptr<WebSocket> ws(new WebSocket(cs, request, response));
-
- std::shared_ptr<ChildProcessSession> session(new ChildProcessSession(ws, loKit, nullptr, std::to_string(_childId)));
-
- ws->setReceiveTimeout(0);
-
- std::string hello("child " + std::to_string(_childId) + " " + std::to_string(Process::id()));
- session->sendTextFrame(hello);
-
- TileQueue queue;
- Thread queueHandlerThread;
- QueueHandler handler(queue);
-
- handler.setSession(session);
- queueHandlerThread.start(handler);
-
- int flags;
- int n;
- do
- {
- char buffer[1024];
- n = ws->receiveFrame(buffer, sizeof(buffer), flags);
-
- if (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE)
- {
- std::string firstLine = getFirstLine(buffer, n);
- StringTokenizer tokens(firstLine, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
-
- // The only kind of messages a child process receives are the single-line ones (?)
- assert(firstLine.size() == static_cast<std::string::size_type>(n));
-
- queue.put(firstLine);
- }
- }
- while (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE);
-
- queue.clear();
- queue.put("eof");
- queueHandlerThread.join();
-
- // Destroy lokit document
- if (session->_loKitDocument)
- session->_loKitDocument->pClass->destroy(session->_loKitDocument);
-
- // Destroy LibreOfficeKit
- loKit->pClass->destroy(loKit);
-
- // wait to finish lo_startmain thread
- pthread_exit(0);
- }
- catch (Exception& exc)
- {
- logger().log(Util::logPrefix() + "Exception: " + exc.what());
- }
- catch (std::exception& exc)
- {
- logger().error(Util::logPrefix() + "Exception: " + exc.what());
- }
-
- exit(Application::EXIT_OK);
-}
-
-int LOOLWSD::createComponent()
-{
- int pid;
-
- _childId = Util::rng::getNext();
-
- if ((pid = fork()) == -1)
- {
- std::cout << "Fork failed." << std::endl;
- return Application::EXIT_UNAVAILABLE;
- }
-
- if (!pid)
- {
- componentMain();
- }
-
- MasterProcessSession::_childProcesses[pid] = _childId;
-
- return Application::EXIT_OK;
-}
-
-void LOOLWSD::startupComponent(int nComponents)
-{
- for (int nCntr = nComponents; nCntr; nCntr--)
- {
- if (createComponent() < 0)
- break;
- }
-}
-
-void LOOLWSD::desktopMain()
-{
-#ifdef __linux
- if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>("loolbroker"), 0, 0, 0) != 0)
- std::cout << Util::logPrefix() << "Cannot set thread name :" << strerror(errno) << std::endl;
-
- setSignals(false);
-#endif
-
- startupComponent(_numPreSpawnedChildren);
-
- while (MasterProcessSession::_childProcesses.size() > 0)
- {
- int status;
- pid_t pid = waitpid(-1, &status, WUNTRACED | WNOHANG);
- if (pid > 0)
- {
- if ( MasterProcessSession::_childProcesses.find(pid) != MasterProcessSession::_childProcesses.end() )
- {
- if ((WIFEXITED(status) || WIFSIGNALED(status) || WTERMSIG(status) ) )
- {
- std::cout << Util::logPrefix() << "One of our known child processes died :" << std::to_string(pid) << std::endl;
- // remove chroot child
- File aWorkSpace(LOOLWSD::childRoot + Path::separator() +
- std::to_string(MasterProcessSession::_childProcesses[pid]));
- if (aWorkSpace.exists())
- aWorkSpace.remove(true);
-
- MasterProcessSession::_childProcesses.erase(pid);
- }
-
- if ( WCOREDUMP(status) )
- std::cout << Util::logPrefix() << "The child process [" << pid << "] produced a core dump." << std::endl;
-
- if ( WIFSTOPPED(status) )
- std::cout << Util::logPrefix() << "The child process was stopped by delivery of a signal." << std::endl;
-
- if ( WSTOPSIG(status) )
- std::cout << Util::logPrefix() << "The child process was stopped." << std::endl;
-
- if ( WIFCONTINUED(status) )
- std::cout << Util::logPrefix() << "The child process was resumed." << std::endl;
- }
- else
- {
- std::cout << Util::logPrefix() << "None of our known child processes died :" << std::to_string(pid) << std::endl;
- }
- }
- else if (pid < 0)
- std::cout << Util::logPrefix() << "Child error: " << strerror(errno);
-
- if (!LOOLWSD::isShutDown && _sharedForkChild.begin()[0] > 0 )
- {
- _namedMutexLOOL.lock();
- _sharedForkChild.begin()[0] = _sharedForkChild.begin()[0] - 1;
- std::cout << Util::logPrefix() << "Create child session, fork new one" << std::endl;
- _namedMutexLOOL.unlock();
- if (createComponent() < 0 )
- break;
- }
-
- ++timeoutCounter;
- if (timeoutCounter == INTERVAL_PROBES)
- {
- timeoutCounter = 0;
- sleep(MAINTENANCE_INTERVAL);
- }
- }
-
- exit(Application::EXIT_OK);
-}
-
-
-int LOOLWSD::createDesktop()
-{
- int pid;
-
- if ((pid = fork()) == -1)
- {
- std::cout << "createDesktop fork failed." << std::endl;
- return Application::EXIT_UNAVAILABLE;
- }
-
- if (!pid)
- {
- desktopMain();
- }
-
- MasterProcessSession::_childProcesses[pid] = pid;
-
- return Application::EXIT_OK;
-}
-
int LOOLWSD::createBroker()
{
Process::Args args;
diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp
index 3f7cfee..e14b0e4 100644
--- a/loolwsd/LOOLWSD.hpp
+++ b/loolwsd/LOOLWSD.hpp
@@ -42,7 +42,6 @@ public:
static std::string childRoot;
static std::string loSubPath;
static std::string jail;
- static Poco::SharedMemory _sharedForkChild;
static Poco::NamedMutex _namedMutexLOOL;
static Poco::UInt64 _childId;
More information about the Libreoffice-commits
mailing list