[Libreoffice-commits] online.git: Branch 'distro/collabora/milestone-7' - loolwsd/LOOLWSD.cpp
loolwsd/LOOLWSD.cpp | 14 +++--- 1 file changed, 7 insertions(+), 7 deletions(-) New commits: commit 5aec6bfcf7ebe2d0104bbd67c8cce7f7f5e366e4 Author: Henry CastroDate: Mon Feb 1 18:01:48 2016 -0400 loolwsd: use EXIT_SOFTWARE to indicate internal error diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index 8948da0..ca909aa 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -866,7 +866,7 @@ namespace Application::instance().logger().error(Util::logPrefix() + "link(\"" + fpath + "\",\"" + newPath.toString() + "\") failed: " + strerror(errno)); -exit(1); +exit(Application::EXIT_SOFTWARE); } break; case FTW_DP: @@ -935,20 +935,20 @@ namespace if (caps == NULL) { Application::instance().logger().error(Util::logPrefix() + "cap_get_proc() failed: " + strerror(errno)); -exit(1); +exit(Application::EXIT_SOFTWARE); } if (cap_set_flag(caps, CAP_EFFECTIVE, sizeof(cap_list)/sizeof(cap_list[0]), cap_list, CAP_CLEAR) == -1 || cap_set_flag(caps, CAP_PERMITTED, sizeof(cap_list)/sizeof(cap_list[0]), cap_list, CAP_CLEAR) == -1) { Application::instance().logger().error(Util::logPrefix() + "cap_set_flag() failed: " + strerror(errno)); -exit(1); +exit(Application::EXIT_SOFTWARE); } if (cap_set_proc(caps) == -1) { Application::instance().logger().error(std::string("cap_set_proc() failed: ") + strerror(errno)); -exit(1); +exit(Application::EXIT_SOFTWARE); } char *capText = cap_to_text(caps, NULL); @@ -1073,13 +1073,13 @@ void LOOLWSD::componentMain() if (chroot(jailPath.toString().c_str()) == -1) { logger().error("chroot(\"" + jailPath.toString() + "\") failed: " + strerror(errno)); -exit(Application::EXIT_UNAVAILABLE); +exit(Application::EXIT_SOFTWARE); } if (chdir("/") == -1) { logger().error(std::string("chdir(\"/\") in jail failed: ") + strerror(errno)); -exit(Application::EXIT_UNAVAILABLE); +exit(Application::EXIT_SOFTWARE); } #ifdef __linux @@ -1106,7 +1106,7 @@ void LOOLWSD::componentMain() if (!loKit) { logger().fatal(Util::logPrefix() + "LibreOfficeKit initialisation failed"); -exit(Application::EXIT_UNAVAILABLE); +exit(Application::EXIT_SOFTWARE); } _namedMutexLOOL.unlock(); ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: Branch 'distro/collabora/milestone-7' - loolwsd/LOOLWSD.cpp loolwsd/LOOLWSD.hpp
loolwsd/LOOLWSD.cpp | 52 +--- loolwsd/LOOLWSD.hpp |6 -- 2 files changed, 49 insertions(+), 9 deletions(-) New commits: commit dbf816b9392db136f3a74c785a7704c3d5d42a05 Author: Henry CastroDate: Mon Feb 1 17:46:56 2016 -0400 loolwsd: add fatal signals handler diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index db2ccac..8948da0 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -657,20 +657,38 @@ LOOLWSD::~LOOLWSD() { } -void LOOLWSD::handleSignal(int aSignal) +void LOOLWSD::handleTerminationSignal(const int aSignal) { -std::cout << Util::logPrefix() << "Signal received: " << strsignal(aSignal) << std::endl; +std::cout << Util::logPrefix() << "Signal received: " + << strsignal(aSignal) << std::endl; LOOLWSD::isShutDown = true; } -void LOOLWSD::setSignals(bool isIgnored) +void LOOLWSD::handleFatalSignal(const int aSignal) +{ +std::cout << Util::logPrefix() << "Fatal signal received: " + << strsignal(aSignal) << std::endl; + #ifdef __linux +struct sigaction aSigAction; + +sigemptyset(_mask); +aSigAction.sa_flags = 0; +aSigAction.sa_handler = SIG_DFL; + +sigaction(aSignal, , NULL); +// let default handler process the signal +kill(Process::id(), aSignal); +#endif +} + +void LOOLWSD::setTerminationSignals() { #ifdef __linux struct sigaction aSigAction; sigemptyset(_mask); aSigAction.sa_flags = 0; -aSigAction.sa_handler = (isIgnored ? SIG_IGN : handleSignal); +aSigAction.sa_handler = handleTerminationSignal; sigaction(SIGTERM, , NULL); sigaction(SIGINT, , NULL); @@ -679,6 +697,23 @@ void LOOLWSD::setSignals(bool isIgnored) #endif } +void LOOLWSD::setFatalSignals() +{ +#ifdef __linux +struct sigaction aSigAction; + +sigemptyset(_mask); +aSigAction.sa_flags = 0; +aSigAction.sa_handler = handleFatalSignal; + +sigaction(SIGSEGV, , NULL); +sigaction(SIGBUS, , NULL); +sigaction(SIGABRT, , NULL); +sigaction(SIGILL, , NULL); +sigaction(SIGFPE, , NULL); +#endif +} + void LOOLWSD::initialize(Application& self) { ServerApplication::initialize(self); @@ -982,7 +1017,8 @@ void LOOLWSD::componentMain() if (prctl(PR_SET_NAME, reinterpret_cast("libreofficekit"), 0, 0, 0) != 0) std::cout << Util::logPrefix() << "Cannot set thread name :" << strerror(errno) << std::endl; -setSignals(false); +setTerminationSignals(); +setFatalSignals(); #endif try @@ -1195,7 +1231,8 @@ void LOOLWSD::desktopMain() if (prctl(PR_SET_NAME, reinterpret_cast("loolbroker"), 0, 0, 0) != 0) std::cout << Util::logPrefix() << "Cannot set thread name :" << strerror(errno) << std::endl; -setSignals(false); +setTerminationSignals(); +setFatalSignals(); #endif _rng.seed(Process::id()); @@ -1309,7 +1346,8 @@ int LOOLWSD::main(const std::vector& /*args*/) if (locale == NULL || std::strcmp(locale, "C") == 0) setlocale(LC_ALL, "en_US.utf8"); -setSignals(false); +setTerminationSignals(); +setFatalSignals(); #endif if (access(cache.c_str(), R_OK | W_OK | X_OK) != 0) diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp index f58917a..8d87cb0 100644 --- a/loolwsd/LOOLWSD.hpp +++ b/loolwsd/LOOLWSD.hpp @@ -56,8 +56,10 @@ public: static const std::string LOKIT_PIDLOG; protected: -static void setSignals(bool bIgnore); -static void handleSignal(int nSignal); +static void setTerminationSignals(); +static void setFatalSignals(); +static void handleTerminationSignal(const int nSignal); +static void handleFatalSignal(const int nSignal); void initialize(Poco::Util::Application& self) override; void uninitialize() override; ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: Branch 'distro/collabora/milestone-7' - loolwsd/LOOLWSD.cpp loolwsd/Util.cpp loolwsd/Util.hpp
loolwsd/LOOLWSD.cpp | 21 ++-- loolwsd/Util.cpp| 54 +++- loolwsd/Util.hpp| 17 3 files changed, 89 insertions(+), 3 deletions(-) New commits: commit 78e19dbedc4f2257bdad63608a8f70e65b486e04 Author: Henry CastroDate: Mon Feb 1 20:14:26 2016 -0400 loolwsd: avoid fork a new child when its exit code is not success diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index ca909aa..d8070e0 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -1227,6 +1227,8 @@ bool LOOLWSD::startupComponent(int nComponents) void LOOLWSD::desktopMain() { +int nChildExitCode = Application::EXIT_OK; + #ifdef __linux if (prctl(PR_SET_NAME, reinterpret_cast("loolbroker"), 0, 0, 0) != 0) std::cout << Util::logPrefix() << "Cannot set thread name :" << strerror(errno) << std::endl; @@ -1248,7 +1250,20 @@ void LOOLWSD::desktopMain() { if ((WIFEXITED(status) || WIFSIGNALED(status))) { -std::cout << Util::logPrefix() << "One of our known child processes died :" << std::to_string(pid) << std::endl; +if (WIFEXITED(status)) +{ +nChildExitCode = Util::getChildStatus(WEXITSTATUS(status)); +std::cout << Util::logPrefix() << "One of our known child processes died :" << std::to_string(pid) + << " exit code " << std::to_string(WEXITSTATUS(status)) << std::endl; +} +else +if (WIFSIGNALED(status)) +{ +nChildExitCode = Util::getSignalStatus(WTERMSIG(status)); +std::cout << Util::logPrefix() << "One of our known child processes died :" << std::to_string(pid) + << " signal code " << strsignal(WTERMSIG(status)) << std::endl; +} + // remove chroot child File aWorkSpace(LOOLWSD::childRoot + Path::separator() + std::to_string(MasterProcessSession::_childProcesses[pid])); @@ -1256,6 +1271,7 @@ void LOOLWSD::desktopMain() aWorkSpace.remove(true); MasterProcessSession::_childProcesses.erase(pid); +timeoutCounter = -1; } if ( WCOREDUMP(status) ) @@ -1289,7 +1305,7 @@ void LOOLWSD::desktopMain() if (MasterProcessSession::_childProcesses.size() + toSpawn < _numPreSpawnedChildren) toSpawn = _numPreSpawnedChildren - MasterProcessSession::_childProcesses.size(); -if (toSpawn > 0) +if (toSpawn > 0 && nChildExitCode == Application::EXIT_OK) { std::cout << Util::logPrefix() << "Create child session, fork new ones: " << toSpawn << std::endl; if (!startupComponent(toSpawn)) @@ -1302,6 +1318,7 @@ void LOOLWSD::desktopMain() { timeoutCounter = 0; sleep(MAINTENANCE_INTERVAL); +nChildExitCode = Application::EXIT_OK; } } diff --git a/loolwsd/Util.cpp b/loolwsd/Util.cpp index faf7518..7980fbd 100644 --- a/loolwsd/Util.cpp +++ b/loolwsd/Util.cpp @@ -84,7 +84,7 @@ namespace Util bool encodeBufferToPNG(unsigned char *pixmap, int width, int height, std::vector& output, LibreOfficeKitTileMode mode) { - + return encodeSubBufferToPNG(pixmap, 0, 0, width, height, width, height, output, mode); } @@ -200,6 +200,58 @@ namespace Util return std::to_string(signo); } } + +int getChildStatus(const int nCode) +{ +int nRetVal; + +switch (static_cast(nCode)) +{ +case LOOLExitCode::LOOL_SECOND_OFFICE: +case LOOLExitCode::LOOL_FATAL_ERROR: +case LOOLExitCode::LOOL_CRASH_WITH_RESTART: +case LOOLExitCode::LOOL_NORMAL_RESTART: +case LOOLExitCode::LOOL_EXIT_SOFTWARE: +nRetVal = EXIT_FAILURE; +break; + +case LOOLExitCode::LOOL_NO_ERROR: +nRetVal = EXIT_SUCCESS; +break; + +default: +nRetVal = EXIT_SUCCESS; +break; +} + +return nRetVal; +} + +int getSignalStatus(const int nCode) +{ +int nRetVal; + +switch (nCode) +{ +case SIGSEGV: +case SIGBUS: +case SIGABRT: +case SIGILL: +case SIGFPE: +case SIGTERM: +case SIGINT: +case SIGQUIT: +case SIGHUP: +nRetVal = EXIT_FAILURE; +break; + +default: +nRetVal = EXIT_SUCCESS; +break; +} + +
[Libreoffice-commits] online.git: Branch 'distro/collabora/milestone-7' - loolwsd/LOOLWSD.cpp
loolwsd/LOOLWSD.cpp | 11 +++ 1 file changed, 11 insertions(+) New commits: commit 38e3da41c833855711c8c02987fb2bbcf5ffbe03 Author: Henry CastroDate: Mon Jan 25 17:23:01 2016 -0400 loolwsd: Log::warn when the thread pool is full When thread pool is full no more connections are accepted. It is confused as a deadlock diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index 0440430..db2ccac 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -1384,8 +1384,19 @@ int LOOLWSD::main(const std::vector& /*args*/) waitForTerminationRequest(); } +std::chrono::steady_clock::time_point lastPoolTime = std::chrono::steady_clock::now(); + while (!LOOLWSD::isShutDown && !LOOLWSD::doTest && MasterProcessSession::_childProcesses.size() > 0) { +const auto duration = (std::chrono::steady_clock::now() - lastPoolTime); +if (duration >= std::chrono::seconds(10)) +{ +if (threadPool.available() == 0) +std::cout << Util::logPrefix() << "The thread pool is full, no more connections are accepted." << std::endl; + +lastPoolTime = std::chrono::steady_clock::now(); +} + pid_t pid = waitpid(-1, , WUNTRACED | WNOHANG); if (pid > 0) { ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: Branch 'distro/collabora/milestone-7' - loolwsd/LOOLWSD.cpp
loolwsd/LOOLWSD.cpp | 16 +++- 1 file changed, 11 insertions(+), 5 deletions(-) New commits: commit a4938fa2dd1700fab32a71f1f6d0817e6a01a56d Author: Jan HolesovskyDate: Thu Jan 21 23:11:01 2016 +0100 loolwsd: Fix /convert-to to handle filenames containing spaces. diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index f18d868..eb6794e 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -260,22 +260,28 @@ public: LOOLSession::Kind kind = LOOLSession::Kind::ToClient; std::shared_ptr session(new MasterProcessSession(ws, kind)); const std::string filePrefix("file://"); -std::string load = "load url=" + filePrefix + fromPath; +std::string encodedFrom; +URI::encode(filePrefix + fromPath, std::string(), encodedFrom); +std::string load = "load url=" + encodedFrom; session->handleInput(load.data(), load.size()); // Convert it to the requested format. Path toPath(fromPath); toPath.setExtension(format); std::string toJailURL = filePrefix + LOOLSession::jailDocumentURL + Path::separator() + toPath.getFileName(); -std::string saveas = "saveas url=" + toJailURL + " format=" + format + " options="; +std::string encodedTo; +URI::encode(toJailURL, std::string(), encodedTo); +std::string saveas = "saveas url=" + encodedTo + " format=" + format + " options="; session->handleInput(saveas.data(), saveas.size()); std::string toURL = session->getSaveAs(); +std::string resultingURL; +URI::decode(toURL, resultingURL); // Send it back to the client. std::string mimeType = "application/octet-stream"; -if (toURL.find(filePrefix) == 0) -toURL = toURL.substr(filePrefix.length()); -response.sendFile(toURL, mimeType); +if (resultingURL.find(filePrefix) == 0) +resultingURL = resultingURL.substr(filePrefix.length()); +response.sendFile(resultingURL, mimeType); } else { ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: Branch 'distro/collabora/milestone-7' - loolwsd/LOOLWSD.cpp
loolwsd/LOOLWSD.cpp | 18 +- 1 file changed, 17 insertions(+), 1 deletion(-) New commits: commit 2f964e74a84903b13996ac4e31271f383bc1fcaf Author: Miklos VajnaDate: Mon Jan 18 16:54:22 2016 +0100 loolwsd: handle WS messages split into multiple frames (cherry picked from commit c8ea8bcacd1bc7503cb86a044d0bf320f0d45355) Conflicts: loolwsd/LOOLWSD.cpp Change-Id: I00199a95fa0a429d29923d0f64980608903227a1 diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index 98092ae..f18d868 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -427,7 +427,23 @@ public: std::string firstLine = getFirstLine(buffer, n); StringTokenizer tokens(firstLine, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM); -if (kind == LOOLSession::Kind::ToClient && firstLine.size() == static_cast(n)) +if ((flags & WebSocket::FrameFlags::FRAME_FLAG_FIN) != WebSocket::FrameFlags::FRAME_FLAG_FIN) +{ +// One WS message split into multiple frames. +std::vector message(buffer, buffer + n); +while (true) +{ +n = ws->receiveFrame(buffer, sizeof(buffer), flags); +message.insert(message.end(), buffer, buffer + n); +if ((flags & WebSocket::FrameFlags::FRAME_FLAG_FIN) == WebSocket::FrameFlags::FRAME_FLAG_FIN) +{ +// No more frames: invoke the handler. +session->handleInput(message.data(), message.size()); +break; +} +} +} +else if (kind == LOOLSession::Kind::ToClient && firstLine.size() == static_cast(n)) { queue.put(firstLine); } ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: Branch 'distro/collabora/milestone-7' - loolwsd/LOOLWSD.cpp
loolwsd/LOOLWSD.cpp | 34 +- 1 file changed, 25 insertions(+), 9 deletions(-) New commits: commit 2532c4d6048f2fea2df3ef2ce09e5df7171b9bcb Author: Jan HolesovskyDate: Wed Jan 13 16:35:55 2016 +0100 loolwsd: More protection when inserting image. diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index 87e1dbe..1043a74 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -298,16 +298,32 @@ public: std::string tmpPath; ConvertToPartHandler handler(tmpPath); 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"; -File(dirPath).createDirectories(); -std::string fileName = dirPath + Path::separator() + form.get("name"); -File(tmpPath).moveTo(fileName); -response.setStatus(HTTPResponse::HTTP_OK); -response.send(); +bool goodRequest = form.has("childid") && form.has("name"); +std::string formName(form.get("name")); + +if (goodRequest && formName.find('/') != std::string::npos) +goodRequest = false; + +if (goodRequest) +{ +try { +std::cout << Util::logPrefix() << "Perform insertfile: " << form.get("childid") << ", " << form.get("name") << std::endl; +std::string dirPath = LOOLWSD::childRoot + Path::separator() + form.get("childid") + LOOLSession::jailDocumentURL + +Path::separator() + "insertfile"; +File(dirPath).createDirectories(); +std::string fileName = dirPath + Path::separator() + formName; +File(tmpPath).moveTo(fileName); + +response.setStatus(HTTPResponse::HTTP_OK); +response.send(); +} +catch (const IOException& exc) +{ + Application::instance().logger().error(Util::logPrefix() + "IOException: " + exc.message()); +response.setStatus(HTTPResponse::HTTP_BAD_REQUEST); +response.send(); +} } else { ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: Branch 'distro/collabora/milestone-7' - loolwsd/LOOLWSD.cpp
loolwsd/LOOLWSD.cpp |8 +--- 1 file changed, 5 insertions(+), 3 deletions(-) New commits: commit 1d2ec09cb8da03f1419391518e2b5aef383c65ce Author: Jan HolesovskyDate: Wed Jan 13 16:54:19 2016 +0100 loolwsd: More protection when inserting image. diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index 1043a74..c1434e1 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -300,16 +300,18 @@ public: Poco::Net::HTMLForm form(request, request.stream(), handler); bool goodRequest = form.has("childid") && form.has("name"); +std::string formChildid(form.get("childid")); std::string formName(form.get("name")); -if (goodRequest && formName.find('/') != std::string::npos) +// protect against attempts to inject something funny here +if (goodRequest && formChildid.find('/') != std::string::npos && formName.find('/') != std::string::npos) goodRequest = false; if (goodRequest) { try { -std::cout << Util::logPrefix() << "Perform insertfile: " << form.get("childid") << ", " << form.get("name") << std::endl; -std::string dirPath = LOOLWSD::childRoot + Path::separator() + form.get("childid") + LOOLSession::jailDocumentURL + +std::cout << Util::logPrefix() << "Perform insertfile: " << formChildid << ", " << formName << std::endl; +std::string dirPath = LOOLWSD::childRoot + Path::separator() + formChildid + LOOLSession::jailDocumentURL + Path::separator() + "insertfile"; File(dirPath).createDirectories(); std::string fileName = dirPath + Path::separator() + formName; ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: Branch 'distro/collabora/milestone-7' - loolwsd/LOOLWSD.cpp
loolwsd/LOOLWSD.cpp |2 +- 1 file changed, 1 insertion(+), 1 deletion(-) New commits: commit ae675490aaf1d980325e7a1c8b20a50f080c8777 Author: Jan HolesovskyDate: Wed Jan 13 16:20:48 2016 +0100 loolwsd: Fix inserting of images into files opened via http:// diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index 154cccd..87e1dbe 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -302,7 +302,7 @@ public: { std::string dirPath = LOOLWSD::childRoot + Path::separator() + form.get("childid") + LOOLSession::jailDocumentURL + Path::separator() + "insertfile"; -File(dirPath).createDirectory(); +File(dirPath).createDirectories(); std::string fileName = dirPath + Path::separator() + form.get("name"); File(tmpPath).moveTo(fileName); ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits