[Libreoffice-commits] online.git: loolwsd/LOOLBroker.cpp loolwsd/LOOLKit.cpp loolwsd/LOOLWSD.cpp loolwsd/MasterProcessSession.cpp loolwsd/MasterProcessSession.hpp
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 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(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(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> _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(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& /*args*/) Util::removeFile(path, true); } -Log::debug("Cleaning up pipe directory [" + pipePath.toString() + "]."); -Util::removeF
[Libreoffice-commits] online.git: loolwsd/LOOLBroker.cpp loolwsd/LOOLKit.cpp loolwsd/LOOLWSD.cpp loolwsd/LOOLWSD.hpp
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 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(8), -[&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(ch
[Libreoffice-commits] online.git: loolwsd/LOOLBroker.cpp loolwsd/LOOLKit.cpp loolwsd/LOOLWSD.cpp loolwsd/LOOLWSD.hpp loolwsd/Makefile.am loolwsd/MasterProcessSession.cpp loolwsd/MasterProcessSession.h
loolwsd/LOOLBroker.cpp | 218 +++ loolwsd/LOOLKit.cpp | 188 + loolwsd/LOOLWSD.cpp |7 - loolwsd/LOOLWSD.hpp | 11 - loolwsd/Makefile.am |2 loolwsd/MasterProcessSession.cpp | 12 +- loolwsd/MasterProcessSession.hpp |4 7 files changed, 224 insertions(+), 218 deletions(-) New commits: commit 9e3d5c0337f9cd1439d4b6b648eb6ac795ff792e Author: Henry Castro Date: Sat Feb 13 10:15:28 2016 -0400 loolwsd: ensure chroot jail every lokit process diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp index 970882e..0b3ab32 100644 --- a/loolwsd/LOOLBroker.cpp +++ b/loolwsd/LOOLBroker.cpp @@ -7,31 +7,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include #include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - #include "Common.hpp" #include "Capabilities.hpp" #include "Util.hpp" @@ -45,15 +22,9 @@ #define LIB_SOFFICEAPP "lib" "sofficeapp" ".so" #define LIB_MERGED "lib" "mergedlo" ".so" -#define JAILED_LOOLKIT_PATH"/usr/bin/loolkit" typedef int (LokHookPreInit) ( const char *install_path, const char *user_profile_path ); -using Poco::Path; -using Poco::File; -using Poco::ThreadLocal; -using Poco::Process; -using Poco::Thread; using Poco::ProcessHandle; const std::string FIFO_FILE = "/tmp/loolwsdfifo"; @@ -64,6 +35,7 @@ const std::string BROKER_PREFIX = "/tmp/lokit"; static int readerChild = -1; static int readerBroker = -1; +static std::string loolkitPath; static std::atomic forkCounter; static std::chrono::steady_clock::time_point lastMaintenanceTime = std::chrono::steady_clock::now(); static unsigned int childCounter = 0; @@ -196,82 +168,6 @@ namespace _childProcesses.erase(it); } } - -ThreadLocal sourceForLinkOrCopy; -ThreadLocal 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) -{ -Log::error("Error: link(\"" + std::string(fpath) + "\",\"" + newPath.toString() + - "\") failed. Exiting."); -exit(Application::EXIT_SOFTWARE); -} -break; -case FTW_DP: -{ -struct stat st; -if (stat(fpath, &st) == -1) -{ -Log::error("Error: stat(\"" + std::string(fpath) + "\") failed."); -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) -{ -Log::error("Error: utime(\"" + newPath.toString() + "\", &ut) failed."); -return 1; -} -} -break; -case FTW_DNR: -Log::error("Cannot read directory '" + std::string(fpath) + "'"); -return 1; -case FTW_NS: -Log::error("nftw: stat failed for '" + std::string(fpath) + "'"); -return 1; -case FTW_SLN: -Log::error("nftw: symlink to nonexistent file: '" + std::string(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) -Log::error("linkOrCopy: nftw() failed for '" + source + "'"); -} } class PipeRunnable: public Runnable @@ -567,18 +463,21 @@ static bool globalPreinit(const std::string &loSubPath) } static int createLibreOfficeKit(const bool sharePages, -
[Libreoffice-commits] online.git: loolwsd/LOOLBroker.cpp loolwsd/LOOLKit.cpp loolwsd/LOOLWSD.cpp
loolwsd/LOOLBroker.cpp | 30 +++--- loolwsd/LOOLKit.cpp| 16 +--- loolwsd/LOOLWSD.cpp|8 3 files changed, 28 insertions(+), 26 deletions(-) New commits: commit 5fd2be332a6f1b7ae90ecdf8b4b2605768a9c730 Author: Henry Castro Date: Mon Feb 1 21:51:42 2016 -0400 loolwsd: use EXIT_SOFTWARE to indicate internal error diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp index 24e8d94..aa9d07a 100644 --- a/loolwsd/LOOLBroker.cpp +++ b/loolwsd/LOOLBroker.cpp @@ -229,7 +229,7 @@ namespace { Log::error("Error: link(\"" + std::string(fpath) + "\",\"" + newPath.toString() + "\") failed. Exiting."); -exit(1); +exit(Application::EXIT_SOFTWARE); } break; case FTW_DP: @@ -592,7 +592,7 @@ static int createLibreOfficeKit(const bool sharePages, { // child lokit_main(loSubPath, jailId, pipe); -_exit(0); +_exit(Application::EXIT_OK); } else { @@ -730,37 +730,37 @@ int main(int argc, char** argv) if (loSubPath.empty()) { Log::error("Error: --losubpath is empty"); -exit(-1); +exit(Application::EXIT_SOFTWARE); } if (sysTemplate.empty()) { Log::error("Error: --losubpath is empty"); -exit(-1); +exit(Application::EXIT_SOFTWARE); } if (loTemplate.empty()) { Log::error("Error: --lotemplate is empty"); -exit(-1); +exit(Application::EXIT_SOFTWARE); } if (childRoot.empty()) { Log::error("Error: --childroot is empty"); -exit(-1); +exit(Application::EXIT_SOFTWARE); } if (numPreSpawnedChildren < 1) { Log::error("Error: --numprespawns is 0"); -exit(-1); +exit(Application::EXIT_SOFTWARE); } if ( (readerBroker = open(FIFO_FILE.c_str(), O_RDONLY) ) < 0 ) { Log::error("Error: failed to open pipe [" + FIFO_FILE + "] read only. Exiting."); -exit(-1); +exit(Application::EXIT_SOFTWARE); } try @@ -786,7 +786,7 @@ int main(int argc, char** argv) if (!File(loolkitPath).exists()) { Log::error("Error: loolkit does not exists at [" + loolkitPath + "]."); -exit(-1); +exit(Application::EXIT_SOFTWARE); } const Path jailPath = Path::forDirectory(childRoot + Path::separator() + jailId); @@ -838,13 +838,13 @@ int main(int argc, char** argv) if (chroot(jailPath.toString().c_str()) == -1) { Log::error("Error: chroot(\"" + jailPath.toString() + "\") failed."); -exit(-1); +exit(Application::EXIT_SOFTWARE); } if (chdir("/") == -1) { Log::error("Error: chdir(\"/\") in jail failed."); -exit(-1); +exit(Application::EXIT_SOFTWARE); } #ifdef __linux @@ -858,7 +858,7 @@ int main(int argc, char** argv) if (mkfifo(FIFO_BROKER.c_str(), 0666) == -1) { Log::error("Error: Failed to create pipe FIFO [" + FIFO_BROKER + "]."); -exit(-1); +exit(Application::EXIT_SOFTWARE); } // Initialize LoKit and hope we can fork and save memory by sharing pages. @@ -868,7 +868,7 @@ int main(int argc, char** argv) if (createLibreOfficeKit(sharePages, loSubPath, jailId) < 0) { Log::error("Error: failed to create children."); -exit(-1); +exit(Application::EXIT_SOFTWARE); } if (numPreSpawnedChildren > 1) @@ -877,7 +877,7 @@ int main(int argc, char** argv) if ( (readerChild = open(FIFO_BROKER.c_str(), O_RDONLY) ) < 0 ) { Log::error("Error: pipe opened for reading."); -exit(-1); +exit(Application::EXIT_SOFTWARE); } PipeRunnable pipeHandler; @@ -991,7 +991,7 @@ int main(int argc, char** argv) close(readerBroker); Log::info("Process [loolbroker] finished."); -return 0; +return Application::EXIT_OK; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index ec3e7b3..f57c7ad 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #define LOK_USE_UNSTABLE_API #include @@ -57,6 +58,7 @@ using Poco::Process; using Poco::Notification; using Poco::NotificationQueue; using Poco::FastMutex; +using Poco::Util::Application; const std::string CHILD_URI = "/loolws/child/"; const std::string LOKIT_BROKER = "/tmp/loolbroker.fifo"; @@ -533,7 +535,7 @@ void lokit_main(const std::string &loSubPath, const std::string& jailId, const s if (loKit == nullptr) { Log::error("Error: LibreOfficeKit initialization failed. Exiting."); -exit(-1); +exit(Application::EXIT_SOFTWARE); } try @@ -544,13 +546,13 @@ void lokit_main(c
[Libreoffice-commits] online.git: loolwsd/LOOLBroker.cpp loolwsd/LOOLKit.cpp loolwsd/LOOLWSD.cpp loolwsd/Util.cpp loolwsd/Util.hpp
loolwsd/LOOLBroker.cpp |3 +- loolwsd/LOOLKit.cpp|3 +- loolwsd/LOOLWSD.cpp|3 +- loolwsd/Util.cpp | 60 + loolwsd/Util.hpp |3 +- 5 files changed, 54 insertions(+), 18 deletions(-) New commits: commit b477f4163619e52e3a46e681612c0afbf28a2acf Author: Henry Castro Date: Mon Feb 1 21:26:19 2016 -0400 loolwsd: add fatal signals handler diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp index f58a4f3..cb93536 100644 --- a/loolwsd/LOOLBroker.cpp +++ b/loolwsd/LOOLBroker.cpp @@ -669,7 +669,8 @@ int main(int argc, char** argv) // Initialization Log::initialize("brk"); -Util::setSignals(false); +Util::setTerminationSignals(); +Util::setFatalSignals(); std::string childRoot; std::string jailId; diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 04e5d82..ec3e7b3 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -517,7 +517,8 @@ void lokit_main(const std::string &loSubPath, const std::string& jailId, const s #ifdef __linux if (prctl(PR_SET_NAME, reinterpret_cast(process_name.c_str()), 0, 0, 0) != 0) Log::error("Cannot set process name to " + process_name + "."); -Util::setSignals(false); +Util::setTerminationSignals(); +Util::setFatalSignals(); #endif Log::debug("Process [" + process_name + "] started."); diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index b5ef7e0..2e59e0e 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -896,7 +896,8 @@ int LOOLWSD::main(const std::vector& /*args*/) setlocale(LC_ALL, "en_US.utf8"); #endif -Util::setSignals(false); +Util::setTerminationSignals(); +Util::setFatalSignals(); if (access(Cache.c_str(), R_OK | W_OK | X_OK) != 0) { diff --git a/loolwsd/Util.cpp b/loolwsd/Util.cpp index ee2b5d1..088620c 100644 --- a/loolwsd/Util.cpp +++ b/loolwsd/Util.cpp @@ -416,7 +416,7 @@ namespace Util } static -void handleSignal(int aSignal) +void handleTerminationSignal(const int aSignal) { if (!TerminationFlag) { @@ -426,37 +426,69 @@ namespace Util TerminationFlag = true; TerminationState = ( aSignal == SIGTERM ? LOOLState::LOOL_ABNORMAL : LOOLState::LOOL_STOPPING ); -Log::info() << "Signal received: " << strsignal(aSignal) << Log::end; -if (aSignal == SIGSEGV || aSignal == SIGBUS) -{ -Log::error() << "\nSegfault! Attach debugger with:\n" - << "sudo gdb --pid=" << Poco::Process::id() << "\n or \n" - << "sudo gdb --q --n --ex 'thread apply all backtrace full' --batch --pid=" - << Poco::Process::id() << "\n" << Log::end; -sleep(10); -} +Log::info() << "Termination signal received: " +<< strsignal(aSignal) << Log::end; } } -void setSignals(bool isIgnored) +void setTerminationSignals() { #ifdef __linux struct sigaction aSigAction; sigemptyset(&aSigAction.sa_mask); aSigAction.sa_flags = 0; -aSigAction.sa_handler = (isIgnored ? SIG_IGN : handleSignal); +aSigAction.sa_handler = handleTerminationSignal; sigaction(SIGTERM, &aSigAction, nullptr); sigaction(SIGINT, &aSigAction, nullptr); sigaction(SIGQUIT, &aSigAction, nullptr); sigaction(SIGHUP, &aSigAction, nullptr); +#endif +} + +static +void handleFatalSignal(const int aSignal) +{ +Log::error() << "Fatal signal received: " + << strsignal(aSignal) << Log::end; if (getenv("LOOL_DEBUG")) { -sigaction(SIGBUS, &aSigAction, nullptr); -sigaction(SIGSEGV, &aSigAction, nullptr); +Log::error() << "\nSegfault! Attach debugger with:\n" + << "sudo gdb --pid=" << Poco::Process::id() << "\n or \n" + << "sudo gdb --q --n --ex 'thread apply all backtrace full' --batch --pid=" + << Poco::Process::id() << "\n" << Log::end; +sleep(10); } + +#ifdef __linux +struct sigaction aSigAction; + +sigemptyset(&aSigAction.sa_mask); +aSigAction.sa_flags = 0; +aSigAction.sa_handler = SIG_DFL; + +sigaction(aSignal, &aSigAction, NULL); +// let default handler process the signal +kill(Poco::Process::id(), aSignal); +#endif +} + +void setFatalSignals() +{ +#ifdef __linux +struct sigaction aSigAction; + +sigemptyset(&aSigAction.sa_mask); +aSigAction.sa_flags = 0; +aSigAction.sa_handler = handleFatalSignal; + +sigaction(SIGSEGV, &aSigAction, NULL); +sigaction(SIGBUS, &aSigAction, NULL); +sigaction(SIGABRT, &aSigAction, NULL); +sigaction(SIG
[Libreoffice-commits] online.git: loolwsd/LOOLBroker.cpp loolwsd/LOOLKit.cpp loolwsd/LOOLWSD.cpp
loolwsd/LOOLBroker.cpp |7 --- loolwsd/LOOLKit.cpp|4 ++-- loolwsd/LOOLWSD.cpp|2 +- 3 files changed, 7 insertions(+), 6 deletions(-) New commits: commit b2b983476c63ca5e77e45bae27ca544a0a29cf4f Author: Ashod Nakashian Date: Fri Jan 8 21:53:57 2016 -0500 loolwsd: more informative warnings Change-Id: I8dba6d003bd5c0b3c16b3cd57c3737638ce56bd1 Reviewed-on: https://gerrit.libreoffice.org/21320 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp index 96d2ea1..a63899b 100644 --- a/loolwsd/LOOLBroker.cpp +++ b/loolwsd/LOOLBroker.cpp @@ -486,7 +486,8 @@ static bool globalPreinit(const std::string &loSubPath) preInit = (LokHookPreInit *)dlsym(handle, "lok_preinit"); if (!preInit) { -Log::warn("Failed to find lok_preinit hook in " + std::string(LIB_SOFFICEAPP) + " library."); +Log::warn("Note: No lok_preinit hook in " + std::string(LIB_SOFFICEAPP) + + " library. Cannot fork, will execv instead."); return false; } @@ -711,7 +712,7 @@ int main(int argc, char** argv) } catch (const Poco::NotFoundException& exc) { -Log::error(std::string("Exception: ") + exc.what()); +Log::warn("Note: LD_BIND_NOW is not set."); } try @@ -720,7 +721,7 @@ int main(int argc, char** argv) } catch (const Poco::NotFoundException& exc) { -Log::error(std::string("Exception: ") + exc.what()); +Log::warn("Note: LOK_VIEW_CALLBACK is not set."); } // The loolkit binary must be in our directory. diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 06a52d4..dfef497 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -915,7 +915,7 @@ int main(int argc, char** argv) } catch (const Poco::NotFoundException& exc) { -Log::error(std::string("Exception: ") + exc.what()); +Log::warn("Note: LD_BIND_NOW is not set."); } try @@ -924,7 +924,7 @@ int main(int argc, char** argv) } catch (const Poco::NotFoundException& exc) { -Log::error(std::string("Exception: ") + exc.what()); +Log::warn("Note: LOK_VIEW_CALLBACK is not set."); } lokit_main(loSubPath, jailId, pipe); diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index dbc4184..1d1a17b 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -823,7 +823,7 @@ int LOOLWSD::main(const std::vector& /*args*/) Log::initialize("wsd"); Poco::Environment::set("LD_BIND_NOW", "1"); -Poco::Environment::set("LOK_VIEW_CALLBACK", "1"); +//Poco::Environment::set("LOK_VIEW_CALLBACK", "1"); #ifdef __linux char *locale = setlocale(LC_ALL, nullptr); ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLBroker.cpp loolwsd/LOOLKit.cpp loolwsd/LOOLWSD.cpp
loolwsd/LOOLBroker.cpp |2 +- loolwsd/LOOLKit.cpp| 11 +-- loolwsd/LOOLWSD.cpp|2 +- 3 files changed, 7 insertions(+), 8 deletions(-) New commits: commit f947b644830c21a2e5d9d7409c42cfb4736e0ab6 Author: Henry Castro Date: Tue Dec 29 00:39:25 2015 -0400 loolwsd: renamed prefix "lool" process We use prefix loolwsd, loolbroker and loolkit to easy grep process search. Also, run_lok_main is not a thread, it is main loop process. diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp index e2dc541..34343cb 100644 --- a/loolwsd/LOOLBroker.cpp +++ b/loolwsd/LOOLBroker.cpp @@ -875,7 +875,7 @@ int main(int argc, char** argv) Process::requestTermination(i.first); } -Log::info("loolbroker finished OK!"); +Log::info("Process [loolbroker] finished."); return 0; } diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index d3d7664..716f9e4 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -529,13 +529,13 @@ void run_lok_main(const std::string &loSubPath, const std::string& childId, cons assert(!childId.empty()); assert(!loSubPath.empty()); -static const std::string thread_name = "libreofficekit"; +static const std::string process_name = "loolkit"; #ifdef __linux -if (prctl(PR_SET_NAME, reinterpret_cast(thread_name.c_str()), 0, 0, 0) != 0) -Log::error("Cannot set thread name to " + thread_name + "."); +if (prctl(PR_SET_NAME, reinterpret_cast(process_name.c_str()), 0, 0, 0) != 0) +Log::error("Cannot set process name to " + process_name + "."); setSignals(false); #endif -Log::debug("Thread [" + thread_name + "] started."); +Log::debug("Process [" + process_name + "] started."); static const std::string instdir_path = #ifdef __APPLE__ @@ -741,7 +741,7 @@ void run_lok_main(const std::string &loSubPath, const std::string& childId, cons loKit->pClass->destroy(loKit.get()); loKit.release(); -Log::debug("Thread [" + thread_name + "] finished."); +Log::info("Process [" + process_name + "] finished."); } #ifndef LOOLKIT_NO_MAIN @@ -831,7 +831,6 @@ int main(int argc, char** argv) run_lok_main(loSubPath, childId, pipe); -Log::info("loolkit finished OK!"); return 0; } diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index 0f4e533..d8989f2 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -1018,7 +1018,7 @@ int LOOLWSD::main(const std::vector& /*args*/) Log::info("Cleaning up childroot directory [" + childRoot + "]."); Util::removeFile(childRoot, true); -Log::info("loolwsd finished OK!"); +Log::info("Process [loolwsd] finished."); return Application::EXIT_OK; } ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLBroker.cpp loolwsd/LOOLKit.cpp loolwsd/LOOLWSD.cpp
loolwsd/LOOLBroker.cpp | 44 loolwsd/LOOLKit.cpp| 20 ++-- loolwsd/LOOLWSD.cpp|9 ++--- 3 files changed, 44 insertions(+), 29 deletions(-) New commits: commit cf972fbed27f96493cf315181f58d30120ef4295 Author: Ashod Nakashian Date: Mon Dec 28 17:23:05 2015 -0500 loolwsd: use full path when spawning loolkit Change-Id: I9875fb7fbbc67915ed62785a3f3d1298a355f0a5 Reviewed-on: https://gerrit.libreoffice.org/20998 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp index 0351739..5c53025 100644 --- a/loolwsd/LOOLBroker.cpp +++ b/loolwsd/LOOLBroker.cpp @@ -46,6 +46,7 @@ #define LIB_SCLO"lib" "sclo" ".so" #define LIB_SWLO"lib" "swlo" ".so" #define LIB_SDLO"lib" "sdlo" ".so" +#define JAILED_LOOLKIT_PATH"/usr/bin/loolkit" typedef int (LokHookPreInit) ( const char *install_path, const char *user_profile_path ); @@ -528,7 +529,6 @@ static int createLibreOfficeKit(const bool sharePages, const std::string& loSubP } else { -const std::string executable = "loolkit"; const std::string pipe = BROKER_PREFIX + std::to_string(childCounter++) + BROKER_SUFIX; if (mkfifo(pipe.c_str(), 0666) < 0) @@ -541,22 +541,30 @@ static int createLibreOfficeKit(const bool sharePages, const std::string& loSubP args.push_back("--losubpath=" + loSubPath); args.push_back("--child=" + childId); args.push_back("--pipe=" + pipe); -args.push_back("--clientport=" + ClientPortNumber); +args.push_back("--clientport=" + std::to_string(ClientPortNumber)); -Log::info("Launching LibreOfficeKit: " + executable + " " + +Log::info("Launching LibreOfficeKit #" + std::to_string(childCounter) + + ": " + JAILED_LOOLKIT_PATH + " " + Poco::cat(std::string(" "), args.begin(), args.end())); -ProcessHandle procChild = Process::launch(executable, args); +ProcessHandle procChild = Process::launch(JAILED_LOOLKIT_PATH, args); child = procChild.id(); -Log::info("Launched kit process: " + std::to_string(child)); +if (!Process::isRunning(procChild)) +{ +// This can happen if we fail to copy it, or bad chroot etc. +Log::error("Error: loolkit was stillborn."); +return -1; +} -if ( ( nFIFOWriter = open(pipe.c_str(), O_WRONLY) ) < 0 ) +if ( (nFIFOWriter = open(pipe.c_str(), O_WRONLY)) < 0 ) { -Log::error("Error: failed to open pipe [" + pipe + "] write only."); +Log::error("Error: failed to open pipe [" + pipe + "] write only. Abandoning child."); +Poco::Process::requestTermination(child); return -1; } } +Log::info() << "Adding Kit #" << childCounter << " PID " << child << Log::end; _childProcesses[child] = nFIFOWriter; return child; } @@ -695,27 +703,31 @@ int main(int argc, char** argv) Log::error(std::string("Exception: ") + exc.what()); } +// The loolkit binary must be in our directory. +const std::string loolkitPath = Poco::Path(argv[0]).parent().toString() + "loolkit"; +if (!File(loolkitPath).exists()) +{ +Log::error("Error: loolkit does not exists at [" + loolkitPath + "]."); +exit(-1); +} + const std::string childId = std::to_string(Util::rng::getNext()); -Path jailPath = Path::forDirectory(childRoot + Path::separator() + childId); +const Path jailPath = Path::forDirectory(childRoot + Path::separator() + childId); +Log::info("Jail path: " + jailPath.toString()); + File(jailPath).createDirectories(); Path jailLOInstallation(jailPath, loSubPath); jailLOInstallation.makeDirectory(); File(jailLOInstallation).createDirectory(); -// Copy (link) LO installation and other necessary files into it from the template - +// Copy (link) LO installation and other necessary files into it from the template. linkOrCopy(sysTemplate, jailPath); linkOrCopy(loTemplate, jailLOInstallation); // It is necessary to deploy loolkit process to chroot jail. -if (!File("loolkit").exists()) -{ -Log::error("loolkit does not exists"); -exit(-1); -} -File("loolkit").copyTo(Path(jailPath, "/usr/bin").toString()); +File(loolkitPath).copyTo(Path(jailPath, JAILED_LOOLKIT_PATH).toString()); // We need this because sometimes the hostname is not resolved std::vector networkFiles = {"/etc/host.conf", "/etc/hosts", "/etc/nsswitch.conf", "/etc/resolv.conf"}; diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 3a4cd08..6b9acce 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -453,14 +453,6 @@ private: void run_lok_main(const std::string &loSubPath, const std::string& ch
[Libreoffice-commits] online.git: loolwsd/LOOLBroker.cpp loolwsd/LOOLKit.cpp loolwsd/LOOLWSD.cpp
loolwsd/LOOLBroker.cpp |8 ++-- loolwsd/LOOLKit.cpp| 36 +--- loolwsd/LOOLWSD.cpp| 17 - 3 files changed, 47 insertions(+), 14 deletions(-) New commits: commit fe0c11333f096a69ed29feb5b6b62931b2f489ab Author: Ashod Nakashian Date: Sat Dec 26 11:33:01 2015 -0500 loolwsd: thread lifecycle markers Change-Id: I704e37e797224c9dbd024fcab3d8e917584be152 Reviewed-on: https://gerrit.libreoffice.org/20975 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp index bb3e3b7..99e4e8d 100644 --- a/loolwsd/LOOLBroker.cpp +++ b/loolwsd/LOOLBroker.cpp @@ -440,10 +440,12 @@ public: pStart = aBuffer; pEnd = aBuffer; +static const std::string thread_name = "broker_pipe_reader"; #ifdef __linux -if (prctl(PR_SET_NAME, reinterpret_cast("pipe_reader"), 0, 0, 0) != 0) -Log::error("Cannot set thread name."); +if (prctl(PR_SET_NAME, reinterpret_cast(thread_name.c_str()), 0, 0, 0) != 0) +Log::error("Cannot set thread name to " + thread_name + "."); #endif +Log::debug("Thread [" + thread_name + "] started."); while (true) { @@ -497,6 +499,8 @@ public: } } } + +Log::debug("Thread [" + thread_name + "] finished."); } private: diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 28cb506..3745089 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -234,6 +234,13 @@ public: void run() { +static const std::string thread_name = "lokit_callback_handler"; +#ifdef __linux +if (prctl(PR_SET_NAME, reinterpret_cast(thread_name.c_str()), 0, 0, 0) != 0) +Log::error("Cannot set thread name to " + thread_name + "."); +#endif +Log::debug("Thread [" + thread_name + "] started."); + while ( true ) { Notification::Ptr aNotification(_queue.waitDequeueNotification()); @@ -268,6 +275,8 @@ public: } else break; } + +Log::debug("Thread [" + thread_name + "] finished."); } private: @@ -290,10 +299,13 @@ public: void run() override { +static const std::string thread_name = "lokit_queue_handler"; #ifdef __linux -if (prctl(PR_SET_NAME, reinterpret_cast("queue_handler"), 0, 0, 0) != 0) -Log::error("Cannot set thread name."); +if (prctl(PR_SET_NAME, reinterpret_cast(thread_name.c_str()), 0, 0, 0) != 0) +Log::error("Cannot set thread name to " + thread_name + "."); #endif +Log::debug("Thread [" + thread_name + "] started."); + try { while (true) @@ -315,6 +327,8 @@ public: Log::error("Unexpected Exception."); raise(SIGABRT); } + +Log::debug("Thread [" + thread_name + "] finished."); } private: @@ -351,10 +365,13 @@ public: void run() override { +static const std::string thread_name = "lokit_connection"; #ifdef __linux -if (prctl(PR_SET_NAME, reinterpret_cast("lokit_connection"), 0, 0, 0) != 0) -Log::error("Cannot set thread name."); +if (prctl(PR_SET_NAME, reinterpret_cast(thread_name.c_str()), 0, 0, 0) != 0) +Log::error("Cannot set thread name to " + thread_name + "."); #endif +Log::debug("Thread [" + thread_name + "] started."); + try { // Open websocket connection between the child process and the @@ -414,6 +431,8 @@ public: { Log::error(std::string("Exception: ") + exc.what()); } + +Log::debug("Thread [" + thread_name + "] finished."); } ~Connection() @@ -453,10 +472,12 @@ void run_lok_main(const std::string &loSubPath, Poco::UInt64 _childId, const std assert (_childId != 0); assert (!loSubPath.empty()); +static const std::string thread_name = "libreofficekit"; #ifdef __linux -if (prctl(PR_SET_NAME, reinterpret_cast("libreofficekit"), 0, 0, 0) != 0) -Log::error("Cannot set thread name."); +if (prctl(PR_SET_NAME, reinterpret_cast(thread_name.c_str()), 0, 0, 0) != 0) +Log::error("Cannot set thread name to " + thread_name + "."); #endif +Log::debug("Thread [" + thread_name + "] started."); static const std::string instdir_path = #ifdef __APPLE__ @@ -644,7 +665,7 @@ void run_lok_main(const std::string &loSubPath, Poco::UInt64 _childId, const std // Destroy LibreOfficeKit loKit->pClass->destroy(loKit.get()); -Log::info("Kit process " + std::to_string(Process::id()) + " finished."); +Log::debug("Thread [" + thread_name + "] finished."); } #ifndef LOOLKIT_NO_MAIN @@ -720,6 +741,7 @@ int main(int argc, char** argv) run_lok_main(loSubPath, _childId, _pipe); +Log::info("loolkit finished OK!"); return 0; } diff --gi