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 <ashod.nakash...@collabora.co.uk> 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 <ashnak...@gmail.com> Tested-by: Ashod Nakashian <ashnak...@gmail.com> 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<std::string> 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& childId, const std::string& pipe) { - if (std::getenv("SLEEPFORDEBUGGER")) - { - std::cerr << "Sleeping " << std::getenv("SLEEPFORDEBUGGER") - << " seconds to attach debugger to process " - << Process::id() << std::endl; - Thread::sleep(std::stoul(std::getenv("SLEEPFORDEBUGGER")) * 1000); - } - struct pollfd aPoll; ssize_t nBytes = -1; char aBuffer[1024*2]; @@ -682,12 +674,20 @@ void run_lok_main(const std::string &loSubPath, const std::string& childId, cons /// Simple argument parsing wrapper / helper for the above. int main(int argc, char** argv) { + if (std::getenv("SLEEPFORDEBUGGER")) + { + std::cerr << "Sleeping " << std::getenv("SLEEPFORDEBUGGER") + << " seconds to attach debugger to process " + << Process::id() << std::endl; + Thread::sleep(std::stoul(std::getenv("SLEEPFORDEBUGGER")) * 1000); + } + + Log::initialize("kit"); + std::string loSubPath; std::string childId; std::string pipe; - Log::initialize("kit"); - for (int i = 1; i < argc; ++i) { char *cmd = argv[i]; diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index e66d872..3b68fed 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -833,13 +833,16 @@ int LOOLWSD::createBroker() args.push_back("--numprespawns=" + std::to_string(NumPreSpawnedChildren)); args.push_back("--clientport=" + std::to_string(ClientPortNumber)); - std::string executable = Path(Application::instance().commandPath()).parent().toString() + "loolbroker"; + const std::string brokerPath = Path(Application::instance().commandPath()).parent().toString() + "loolbroker"; - Log::info("Launching Broker: " + executable + " " + + const auto childIndex = MasterProcessSession::_childProcesses.size() + 1; + Log::info("Launching Broker #" + std::to_string(childIndex) + + ": " + brokerPath + " " + Poco::cat(std::string(" "), args.begin(), args.end())); - ProcessHandle child = Process::launch(executable, args); + ProcessHandle child = Process::launch(brokerPath, args); + Log::info() << "Adding Broker #" << childIndex << " PID " << child.id() << Log::end; MasterProcessSession::_childProcesses[child.id()] = child.id(); return Application::EXIT_OK; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits