loolwsd/Admin.cpp | 13 ++--- loolwsd/Admin.hpp | 10 +--- loolwsd/ChildProcessSession.cpp | 5 -- loolwsd/DocumentBroker.hpp | 2 loolwsd/IoUtil.cpp | 3 - loolwsd/LOOLForKit.cpp | 43 +++++++----------- loolwsd/LOOLKit.cpp | 33 ++++++-------- loolwsd/LOOLSession.cpp | 4 - loolwsd/LOOLWSD.cpp | 91 +++++++++++++++++++-------------------- loolwsd/LOOLWSD.hpp | 4 - loolwsd/MasterProcessSession.cpp | 2 loolwsd/QueueHandler.hpp | 3 - loolwsd/README | 50 ++++++++++----------- loolwsd/Util.cpp | 26 ++++++----- loolwsd/Util.hpp | 7 ++- loolwsd/debian/loolwsd.postinst | 2 loolwsd/loolstat | 2 loolwsd/loolwsd.spec.in | 2 18 files changed, 144 insertions(+), 158 deletions(-)
New commits: commit 175bd4c9e2b31dbd1d5cfbfcf0c91261b56ce085 Author: Tor Lillqvist <t...@collabora.com> Date: Thu Apr 7 11:52:48 2016 +0300 Use the actual current process names here, too diff --git a/loolwsd/loolstat b/loolwsd/loolstat index 642c891..2c0e3f2 100755 --- a/loolwsd/loolstat +++ b/loolwsd/loolstat @@ -64,7 +64,7 @@ fi $PSTREE -a -c -h -A -p $LOOLWSD_PID; # get the number of running processes. -PROCESS=$($PSTREE -a -h -A -p $LOOLWSD_PID | $SED -e "s/\`//g" | $TR -d ' |-' | $GREP -E '^loolwsd|^loolbroker|^libreofficekit' | $WC -l); +PROCESS=$($PSTREE -a -h -A -p $LOOLWSD_PID | $SED -e "s/\`//g" | $TR -d ' |-' | $GREP -E '^loolwsd|^loolforkit|^loolkit' | $WC -l); # get the number of running threads. THREADS=$($PSTREE -a -h -A -p $LOOLWSD_PID | $GREP -o '{.*}' | $WC -l); commit 931550b43512f7d6f7e9075ab9fc1b10aad7604b Author: Tor Lillqvist <t...@collabora.com> Date: Thu Apr 7 11:49:26 2016 +0300 Quite essential to change loolbroker to loolforkit here, too diff --git a/loolwsd/debian/loolwsd.postinst b/loolwsd/debian/loolwsd.postinst index d2b50ec..7363fd6 100755 --- a/loolwsd/debian/loolwsd.postinst +++ b/loolwsd/debian/loolwsd.postinst @@ -4,7 +4,7 @@ set -e case "$1" in configure) - setcap cap_fowner,cap_mknod,cap_sys_chroot=ep /usr/bin/loolbroker || true + setcap cap_fowner,cap_mknod,cap_sys_chroot=ep /usr/bin/loolforkit || true adduser --quiet --system --group --home /opt/lool lool mkdir -p /var/cache/loolwsd && chown lool: /var/cache/loolwsd diff --git a/loolwsd/loolwsd.spec.in b/loolwsd/loolwsd.spec.in index bae0835..555a6fd 100644 --- a/loolwsd/loolwsd.spec.in +++ b/loolwsd/loolwsd.spec.in @@ -69,7 +69,7 @@ echo "0 0 */1 * * root find /var/cache/loolwsd -name \"*.png\" -a -atime +10 -ex %service_add_pre loolwsd.service %post -setcap cap_fowner,cap_mknod,cap_sys_chroot=ep /usr/bin/loolbroker +setcap cap_fowner,cap_mknod,cap_sys_chroot=ep /usr/bin/loolforkit getent group %{group} >/dev/null || groupadd -r %{group} getent passwd %{owner} >/dev/null || useradd -g %{group} -r %{owner} commit 84cd6bbcebdb47503a049434359ab0369fff3626 Author: Tor Lillqvist <t...@collabora.com> Date: Thu Apr 7 11:27:43 2016 +0300 Try to be more consistent in terminology The "Broker" process is called "ForKit" now. The only things called "broker" now are the DocumentBroker objects in the WSD process. diff --git a/loolwsd/Admin.cpp b/loolwsd/Admin.cpp index e884550..2d7e2a8 100644 --- a/loolwsd/Admin.cpp +++ b/loolwsd/Admin.cpp @@ -126,7 +126,7 @@ void AdminRequestHandler::handleWSRequests(HTTPServerRequest& request, HTTPServe if (tokens[0] == "stats") { //TODO: Collect stats and reply back to admin. - // We need to ask Broker to give us some numbers on docs/clients/etc. + // We need to ask ForKit to give us some numbers on docs/clients/etc. // But we can also collect some memory info using system calls. std::string statsResponse; @@ -194,7 +194,7 @@ void AdminRequestHandler::handleWSRequests(HTTPServerRequest& request, HTTPServe { if (std::stoi(tokens[1])) { - IoUtil::writeFIFO(LOOLWSD::BrokerWritePipe, firstLine + "\n"); + IoUtil::writeFIFO(LOOLWSD::ForKitWritePipe, firstLine + "\n"); } } catch(std::exception& e) @@ -424,7 +424,7 @@ void Admin::rescheduleCpuTimer(unsigned interval) unsigned Admin::getTotalMemoryUsage(AdminModel& model) { - unsigned totalMem = Util::getMemoryUsage(_brokerPid); + unsigned totalMem = Util::getMemoryUsage(_forKitPid); totalMem += model.getTotalMemoryUsage(); totalMem += Util::getMemoryUsage(Poco::Process::id()); diff --git a/loolwsd/Admin.hpp b/loolwsd/Admin.hpp index a235669..c5a6258 100644 --- a/loolwsd/Admin.hpp +++ b/loolwsd/Admin.hpp @@ -55,8 +55,8 @@ public: /// Update the Admin Model. void update(const std::string& message); - /// Set the broker ProcessID. - void setBrokerPid(const int brokerPid) { _brokerPid = brokerPid; } + /// Set the forkit process id. + void setForKitPid(const int forKitPid) { _forKitPid = forKitPid; } /// Callers must ensure that modelMutex is acquired AdminModel& getModel(); @@ -83,7 +83,7 @@ private: private: AdminModel _model; std::mutex _modelMutex; - int _brokerPid; + int _forKitPid; Poco::Util::Timer _memStatsTimer; Poco::Util::TimerTask::Ptr _memStatsTask; @@ -92,10 +92,6 @@ private: Poco::Util::Timer _cpuStatsTimer; Poco::Util::TimerTask::Ptr _cpuStatsTask; unsigned _cpuStatsTaskInterval = 5000; - - static Poco::Process::PID BrokerPid; - static int BrokerPipe; - static int AdminNotifyPipe; }; class MemoryStats : public Poco::Util::TimerTask diff --git a/loolwsd/LOOLForKit.cpp b/loolwsd/LOOLForKit.cpp index f4fc35f..cde3c14 100644 --- a/loolwsd/LOOLForKit.cpp +++ b/loolwsd/LOOLForKit.cpp @@ -43,13 +43,13 @@ using Poco::Util::Application; static std::atomic<unsigned> ForkCounter( 0 ); static unsigned int ChildCounter = 0; -static int ReaderBroker = -1; +static int pipeFd = -1; class ChildDispatcher { public: ChildDispatcher() : - _wsdPipeReader("wsd_pipe_rd", ReaderBroker) + _wsdPipeReader("wsd_pipe_rd", pipeFd) { } @@ -63,7 +63,7 @@ public: private: void handleInput(const std::string& message) { - Log::info("Broker command: [" + message + "]."); + Log::info("ForKit command: [" + message + "]."); StringTokenizer tokens(message, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM); @@ -92,7 +92,7 @@ static int createLibreOfficeKit(const std::string& childRoot, if (!(pid = fork())) { // quicker than a generic socket closing approach. - close(ReaderBroker); + close(pipeFd); // child if (std::getenv("SLEEPKITFORDEBUGGER")) @@ -122,19 +122,12 @@ static int createLibreOfficeKit(const std::string& childRoot, static void printArgumentHelp() { std::cout << "Usage: loolforkit [OPTION]..." << std::endl; - std::cout << " Single threaded process broker that spawns lok instances" << std::endl; - std::cout << " note: running this standalone is not possible, it is spawned by the loolwsd" << std::endl; + std::cout << " Single-threaded process that spawns lok instances" << std::endl; + std::cout << " Note: Running this standalone is not possible. It is spawned by loolwsd" << std::endl; std::cout << " and is controlled via a pipe." << std::endl; std::cout << "" << std::endl; - std::cout << " Some parameters are required and passed on to the lok instance:" << std::endl; - std::cout << " --losubpath=<path> path to chroot for child to live inside." << std::endl; - std::cout << " --childroot=<path> path to chroot for child to live inside." << std::endl; - std::cout << " --systemplate=<path> path of system template to pre-populate chroot with." << std::endl; - std::cout << " --lotemplate=<path> path of libreoffice template to pre-populate chroot with." << std::endl; - std::cout << " --losubpath=<path> path to libreoffice install" << std::endl; } -// Broker process int main(int argc, char** argv) { if (std::getenv("SLEEPFORDEBUGGER")) @@ -209,7 +202,7 @@ int main(int argc, char** argv) 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 ) + if ( (pipeFd = open(pipeLoolwsd.c_str(), O_RDONLY) ) < 0 ) { Log::syserror("Failed to open pipe [" + pipeLoolwsd + "] for reading. Exiting."); std::exit(Application::EXIT_SOFTWARE); @@ -229,7 +222,7 @@ int main(int argc, char** argv) } ChildDispatcher childDispatcher; - Log::info("loolbroker is ready."); + Log::info("ForKit process is ready."); Timestamp startTime; @@ -265,9 +258,9 @@ int main(int argc, char** argv) } } - close(ReaderBroker); + close(pipeFd); - Log::info("Process [loolbroker] finished."); + Log::info("ForKit process finished."); return Application::EXIT_OK; } diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index db91acd..0df0813 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -156,8 +156,8 @@ void forkChildren(int number) assert(!newChildrenMutex.try_lock()); // check it is held. const std::string aMessage = "spawn " + std::to_string(number) + "\n"; - Log::debug("MasterToBroker: " + aMessage.substr(0, aMessage.length() - 1)); - IoUtil::writeFIFO(LOOLWSD::BrokerWritePipe, aMessage); + Log::debug("MasterToForKit: " + aMessage.substr(0, aMessage.length() - 1)); + IoUtil::writeFIFO(LOOLWSD::ForKitWritePipe, aMessage); } void preForkChildren() @@ -954,7 +954,7 @@ private: }; std::atomic<unsigned> LOOLWSD::NextSessionId; -int LOOLWSD::BrokerWritePipe = -1; +int LOOLWSD::ForKitWritePipe = -1; std::string LOOLWSD::Cache = LOOLWSD_CACHEDIR; std::string LOOLWSD::SysTemplate; std::string LOOLWSD::LoTemplate; @@ -1202,7 +1202,7 @@ void LOOLWSD::displayVersion() std::cout << LOOLWSD_VERSION << std::endl; } -Process::PID LOOLWSD::createBroker() +Process::PID LOOLWSD::createForKit() { Process::Args args; @@ -1212,12 +1212,12 @@ Process::PID LOOLWSD::createBroker() args.push_back("--childroot=" + ChildRoot); args.push_back("--clientport=" + std::to_string(ClientPortNumber)); - const std::string brokerPath = Path(Application::instance().commandPath()).parent().toString() + "loolforkit"; + const std::string forKitPath = Path(Application::instance().commandPath()).parent().toString() + "loolforkit"; - Log::info("Launching kit forker #1: " + brokerPath + " " + + Log::info("Launching forkit process: " + forKitPath + " " + Poco::cat(std::string(" "), args.begin(), args.end())); - ProcessHandle child = Process::launch(brokerPath, args); + ProcessHandle child = Process::launch(forKitPath, args); return child.id(); } @@ -1321,15 +1321,16 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/) exit(Application::EXIT_SOFTWARE); } - const Process::PID brokerPid = createBroker(); - if (brokerPid < 0) + const Process::PID forKitPid = createForKit(); + if (forKitPid < 0) { - Log::error("Failed to spawn loolBroker."); + Log::error("Failed to spawn loolforkit."); return Application::EXIT_SOFTWARE; } // Init the Admin manager - Admin::instance().setBrokerPid(brokerPid); + Admin::instance().setForKitPid(forKitPid); + // Init the file server FileServer fileServer; @@ -1360,7 +1361,7 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/) srv2.start(); - if ( (BrokerWritePipe = open(pipeLoolwsd.c_str(), O_WRONLY) ) < 0 ) + if ( (ForKitWritePipe = open(pipeLoolwsd.c_str(), O_WRONLY) ) < 0 ) { Log::syserror("Failed to open pipe [" + pipeLoolwsd + "] for writing."); return Application::EXIT_SOFTWARE; @@ -1384,10 +1385,10 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/) int status = 0; while (!TerminationFlag && !LOOLWSD::DoTest) { - const pid_t pid = waitpid(brokerPid, &status, WUNTRACED | WNOHANG); + const pid_t pid = waitpid(forKitPid, &status, WUNTRACED | WNOHANG); if (pid > 0) { - if (brokerPid == pid) + if (forKitPid == pid) { if (WIFEXITED(status)) { @@ -1511,14 +1512,14 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/) threadPool.joinAll(); // Terminate child processes - IoUtil::writeFIFO(LOOLWSD::BrokerWritePipe, "eof\n"); - Log::info("Requesting child process " + std::to_string(brokerPid) + " to terminate"); - Util::requestTermination(brokerPid); + IoUtil::writeFIFO(ForKitWritePipe, "eof\n"); + Log::info("Requesting child process " + std::to_string(forKitPid) + " to terminate"); + Util::requestTermination(forKitPid); - // wait broker process finish - waitpid(brokerPid, &status, WUNTRACED); + // Wait for forkit process finish + waitpid(forKitPid, &status, WUNTRACED); - close(BrokerWritePipe); + close(ForKitWritePipe); Log::info("Cleaning up childroot directory [" + ChildRoot + "]."); std::vector<std::string> jails; diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp index 6cd8c80..0640aba 100644 --- a/loolwsd/LOOLWSD.hpp +++ b/loolwsd/LOOLWSD.hpp @@ -37,7 +37,7 @@ public: // so just keep these as statics. static std::atomic<unsigned> NextSessionId; static unsigned int NumPreSpawnedChildren; - static int BrokerWritePipe; + static int ForKitWritePipe; static bool DoTest; static std::string Cache; static std::string SysTemplate; @@ -65,7 +65,7 @@ private: void initializeSSL(); void displayHelp(); void displayVersion(); - Poco::Process::PID createBroker(); + Poco::Process::PID createForKit(); /// Reads and processes path entries with the given property /// from the configuration. diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp index 0072b8d..5e5047f 100644 --- a/loolwsd/MasterProcessSession.cpp +++ b/loolwsd/MasterProcessSession.cpp @@ -780,7 +780,7 @@ void MasterProcessSession::dispatchChild() // request again new URL session const std::string message = "request " + getId() + " " + _docBroker->getDocKey() + '\n'; Log::trace("MasterToBroker: " + message.substr(0, message.length()-1)); - IoUtil::writeFIFO(LOOLWSD::BrokerWritePipe, message); + IoUtil::writeFIFO(LOOLWSD::ForKitWritePipe, message); } } diff --git a/loolwsd/README b/loolwsd/README index 3cedf85..a7f409f 100644 --- a/loolwsd/README +++ b/loolwsd/README @@ -183,24 +183,24 @@ websocket. Architecture ------------ -There are three processes: LoolWSD, LoolBroker, and LoolKit. +There are three processes: LoolWSD, LoolForKit, and LoolKit. WSD is the top-level server and is intended to run as a service. -It is responsible for spawning Broker and listening on public -port for Client connections. +It is responsible for spawning ForKit and listening on public +port for client connections. -The Broker is only responsible for spawning (or forking) Kit -instances. There is only one Broker per WSD instance and -there is one Kit instance per document. +The ForKit is only responsible for forking Kit instances. There is +only one ForKit per WSD instance and there is one Kit instance per +document. WSD listens on a public port and using internal pipes requests -the Broker to fire a child (Kit) instance to host documents. -The Broker then has to find an existing Kit that hosts that +the ForKit to fire a child (Kit) instance to host documents. +The ForKit then has to find an existing Kit that hosts that document, based on the public URI as unique key, and forward the request to this existing Kit, which then loads a new view to the document. -There is an additional pipe that kit processes and broker have +There is an additional pipe that kit processes and ForKit have write access to. This pipe is 'notify' pipe. All the important changes are notified on this pipe. The pipe is read by the admin manager continously and it keeps updating the AdminModel object. @@ -211,8 +211,8 @@ to get live notifications about, and to update the UI accordingly. Whether a document is loaded for the first time, or this is a new view on an existing one, the Kit connects via a socket to WSD on an internal port. WSD acts as a bridge between -the Client and Kit by tunnelling the traffic between the two -sockets (that which is between the Client and WSD and the one +the client and Kit by tunnelling the traffic between the two +sockets (that which is between the client and WSD and the one between WSD and Kit). File System @@ -224,24 +224,24 @@ here we'll designate it as: /childroot -Before spawning a Broker instance, WSD needs to generate a random +Before spawning a ForKit instance, WSD needs to generate a random Jail-ID to use as the jail directory name. This JailID is then -passed to Broker as argument jailid. +passed to ForKit as argument jailid. Note: for security reasons, this directory name is randomly generated -and should not be given out to the Client. Since there is only one -Broker per WSD instance, there is also one JailID between them. +and should not be given out to the client. Since there is only one +ForKit per WSD instance, there is also one JailID between them. -The Broker creates a chroot in this directory (the jail directory): +The ForKit creates a chroot in this directory (the jail directory): /childroot/jailid/ -Broker copies the LO instdir (essentially installs LO in the chroot), +ForKit copies the LO instdir (essentially installs LO in the chroot), then copies the Kit binary into the jail directory upon startup. Once done, it chroot-s and drops caps. -Broker then waits on a read pipe to which WSD writes when a new -request from a Client is received. Broker is responsible for spawning +ForKit then waits on a read pipe to which WSD writes when a new +request from a client is received. ForKit is responsible for spawning (or forking) Kit instances. For our purposes, it doesn't matter whether Kit is spawned or forked. @@ -254,22 +254,22 @@ root within the jail is /user/docs. The absolute path on the system Within this path, each document gets its own sub-directory based on another random Child-ID (which could be the Process ID of the Kit). -This ChildId will be given out to Clients to facilitate the insertion -and downloading of documents. (Although strictly speaking the Client +This ChildId will be given out to clients to facilitate the insertion +and downloading of documents. (Although strictly speaking the client can use the main document URI as key, this is the current design.) /childroot/jailid/user/docs/childid -A request from a Client to load a document will trigger the following +A request from a client to load a document will trigger the following chain of events. - WSD public socket will receive the connection request followed by a "load" command. - WSD creates MasterProcessSession (ToClient) to handle the client traffic. -- MasterProcessSession requests Broker to find or spawn Kit for +- MasterProcessSession requests ForKit to find or spawn Kit for the given URI. -- Broker sends Kit request to host URI via pipe. +- ForKit sends Kit request to host URI via pipe. - Kit connects to WSD on an internal port. - WSD creates another MasterProcessSession (ToPrisoner) to service Kit. - MasterProcessSession (ToClient) is linked to the ToPrisoner instance, @@ -277,7 +277,7 @@ chain of events. (via ToPrisoner) the load request to Kit. - Kit loads the document and sets up callbacks with LOKit. - MasterProcessSession (ToClient) and MasterProcessSession (ToPrisoner) - tunnel the traffic between Client and Kit both ways. + tunnel the traffic between client and Kit both ways. Coding style commit d28354c6a65c253983ae4b88547c078a6db9a43d Author: Tor Lillqvist <t...@collabora.com> Date: Thu Apr 7 11:11:23 2016 +0300 Bin unused variables diff --git a/loolwsd/LOOLForKit.cpp b/loolwsd/LOOLForKit.cpp index 0454d07..f4fc35f 100644 --- a/loolwsd/LOOLForKit.cpp +++ b/loolwsd/LOOLForKit.cpp @@ -40,9 +40,6 @@ using Poco::Thread; using Poco::Timestamp; using Poco::Util::Application; -static const std::string BROKER_SUFIX = ".fifo"; -static const std::string BROKER_PREFIX = "lokit"; - static std::atomic<unsigned> ForkCounter( 0 ); static unsigned int ChildCounter = 0; commit c520aa4f05133f1209e0bd09c8f1e234e36ae4dd Author: Tor Lillqvist <t...@collabora.com> Date: Thu Apr 7 11:10:11 2016 +0300 These are not warnings diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index 63064bd..db91acd 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -283,7 +283,7 @@ private: auto session = std::make_shared<MasterProcessSession>(id, LOOLSession::Kind::ToClient, ws, docBroker, nullptr); docBroker->addWSSession(id, session); unsigned wsSessionsCount = docBroker->getWSSessionsCount(); - Log::warn(docKey + ", ws_sessions++: " + std::to_string(wsSessionsCount)); + Log::trace(docKey + ", ws_sessions++: " + std::to_string(wsSessionsCount)); session->setEditLock(true); docBroker->incSessions(); lock.unlock(); @@ -484,7 +484,7 @@ private: docBroker->addWSSession(id, session); unsigned wsSessionsCount = docBroker->getWSSessionsCount(); - Log::warn(docKey + ", ws_sessions++: " + std::to_string(wsSessionsCount)); + Log::trace(docKey + ", ws_sessions++: " + std::to_string(wsSessionsCount)); if (wsSessionsCount == 1) session->setEditLock(true); @@ -531,7 +531,7 @@ private: docBroker->removeWSSession(id); wsSessionsCount = docBroker->getWSSessionsCount(); - Log::warn(docKey + ", ws_sessions--: " + std::to_string(wsSessionsCount)); + Log::trace(docKey + ", ws_sessions--: " + std::to_string(wsSessionsCount)); Log::info("Finishing GET request handler for session [" + id + "]. Joining the queue."); queue->put("eof"); commit acc59a2ea54c7b0f620b85a50ff5233d9e158043 Author: Tor Lillqvist <t...@collabora.com> Date: Thu Apr 7 11:04:05 2016 +0300 Make error messages more consistent and use Log::syserror() in more places A call to Log::error() should be enough to indicate that it is an error. We don't need to prefix the message with the string "Error: " in some cases but not others. (If we do want such a prefix for all errors, surely then we should add it in the actual Log::error() function.) Also, change some more Log::error() calls to Log::syserror() where appropriate. diff --git a/loolwsd/LOOLForKit.cpp b/loolwsd/LOOLForKit.cpp index 495a1ce..0454d07 100644 --- a/loolwsd/LOOLForKit.cpp +++ b/loolwsd/LOOLForKit.cpp @@ -214,7 +214,7 @@ int main(int argc, char** argv) const std::string pipeLoolwsd = Path(pipePath, FIFO_LOOLWSD).toString(); if ( (ReaderBroker = open(pipeLoolwsd.c_str(), O_RDONLY) ) < 0 ) { - Log::syserror("Error: failed to open pipe [" + pipeLoolwsd + "] read only. Exiting."); + Log::syserror("Failed to open pipe [" + pipeLoolwsd + "] for reading. Exiting."); std::exit(Application::EXIT_SOFTWARE); } @@ -227,7 +227,7 @@ int main(int argc, char** argv) // We must have at least one child, more are created dynamically. if (createLibreOfficeKit(childRoot, sysTemplate, loTemplate, loSubPath) < 0) { - Log::error("Error: failed to create a kit process."); + Log::error("Failed to create a kit process."); std::exit(Application::EXIT_SOFTWARE); } @@ -254,7 +254,7 @@ int main(int argc, char** argv) { if (createLibreOfficeKit(childRoot, sysTemplate, loTemplate, loSubPath) < 0) { - Log::error("Error: failed to create a kit process."); + Log::error("Failed to create a kit process."); } else { diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 57862b2..205a1ad 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -118,7 +118,7 @@ namespace File(newPath.parent()).createDirectories(); if (link(fpath, newPath.toString().c_str()) == -1) { - Log::error("Error: link(\"" + std::string(fpath) + "\",\"" + newPath.toString() + + Log::syserror("link(\"" + std::string(fpath) + "\",\"" + newPath.toString() + "\") failed. Exiting."); std::exit(Application::EXIT_SOFTWARE); } @@ -128,7 +128,7 @@ namespace struct stat st; if (stat(fpath, &st) == -1) { - Log::error("Error: stat(\"" + std::string(fpath) + "\") failed."); + Log::syserror("stat(\"" + std::string(fpath) + "\") failed."); return 1; } if (!shouldCopyDir(relativeOldPath)) @@ -142,7 +142,7 @@ namespace ut.modtime = st.st_mtime; if (utime(newPath.toString().c_str(), &ut) == -1) { - Log::error("Error: utime(\"" + newPath.toString() + "\", &ut) failed."); + Log::syserror("utime(\"" + newPath.toString() + "\") failed."); return 1; } } @@ -185,7 +185,7 @@ namespace caps = cap_get_proc(); if (caps == nullptr) { - Log::error("Error: cap_get_proc() failed."); + Log::syserror("cap_get_proc() failed."); std::exit(1); } @@ -196,13 +196,13 @@ namespace 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) { - Log::error("Error: cap_set_flag() failed."); + Log::syserror("cap_set_flag() failed."); std::exit(1); } if (cap_set_proc(caps) == -1) { - Log::error("Error: cap_set_proc() failed."); + Log::syserror("cap_set_proc() failed."); std::exit(1); } @@ -925,7 +925,7 @@ void lokit_main(const std::string& childRoot, Log::debug("symlink(\"" + symlinkTarget + "\",\"" + symlinkSource.toString() + "\")"); if (symlink(symlinkTarget.c_str(), symlinkSource.toString().c_str()) == -1) { - Log::error("Error: symlink(\"" + symlinkTarget + "\",\"" + symlinkSource.toString() + "\") failed"); + Log::syserror("symlink(\"" + symlinkTarget + "\",\"" + symlinkSource.toString() + "\") failed"); throw Exception("symlink() failed"); } @@ -972,26 +972,26 @@ void lokit_main(const std::string& childRoot, S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH, makedev(1, 8)) != 0) { - Log::error("Error: mknod(" + jailPath.toString() + "/dev/random) failed."); + Log::syserror("mknod(" + jailPath.toString() + "/dev/random) failed."); } 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) { - Log::error("Error: mknod(" + jailPath.toString() + "/dev/urandom) failed."); + Log::syserror("mknod(" + jailPath.toString() + "/dev/urandom) failed."); } Log::info("chroot(\"" + jailPath.toString() + "\")"); if (chroot(jailPath.toString().c_str()) == -1) { - Log::error("Error: chroot(\"" + jailPath.toString() + "\") failed."); + Log::syserror("chroot(\"" + jailPath.toString() + "\") failed."); std::exit(Application::EXIT_SOFTWARE); } if (chdir("/") == -1) { - Log::error("Error: chdir(\"/\") in jail failed."); + Log::syserror("chdir(\"/\") in jail failed."); std::exit(Application::EXIT_SOFTWARE); } @@ -1004,7 +1004,7 @@ void lokit_main(const std::string& childRoot, loKit = lok_init_2(instdir_path.c_str(), "file:///user"); if (loKit == nullptr) { - Log::error("Error: LibreOfficeKit initialization failed. Exiting."); + Log::error("LibreOfficeKit initialization failed. Exiting."); std::exit(Application::EXIT_SOFTWARE); } diff --git a/loolwsd/LOOLSession.cpp b/loolwsd/LOOLSession.cpp index 3272af6..a80b65b 100644 --- a/loolwsd/LOOLSession.cpp +++ b/loolwsd/LOOLSession.cpp @@ -73,7 +73,7 @@ void LOOLSession::sendTextFrame(const std::string& text) { if (!_ws) { - Log::error("Error: No socket to send " + getAbbreviatedMessage(text.c_str(), text.size()) + " to."); + Log::error("No socket to send " + getAbbreviatedMessage(text.c_str(), text.size()) + " to."); return; } else @@ -94,7 +94,7 @@ void LOOLSession::sendBinaryFrame(const char *buffer, int length) { if (!_ws) { - Log::error("Error: No socket to send binary frame of " + std::to_string(length) + " bytes to."); + Log::error("No socket to send binary frame of " + std::to_string(length) + " bytes to."); return; } else diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index 688aff1..63064bd 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -1281,14 +1281,14 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/) const Path pipePath = Path::forDirectory(ChildRoot + Path::separator() + FIFO_PATH); if (!File(pipePath).exists() && !File(pipePath).createDirectory()) { - Log::error("Error: Failed to create pipe directory [" + pipePath.toString() + "]."); + Log::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) < 0 && errno != EEXIST) { - Log::error("Error: Failed to create pipe FIFO [" + pipeLoolwsd + "]."); + Log::syserror("Failed to create pipe FIFO [" + pipeLoolwsd + "]."); return Application::EXIT_SOFTWARE; } @@ -1298,26 +1298,26 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/) const std::string pipeNotify = Path(pipePath, FIFO_ADMIN_NOTIFY).toString(); if (mkfifo(pipeNotify.c_str(), 0666) < 0 && errno != EEXIST) { - Log::syserror("Error: Failed to create pipe FIFO [" + std::string(FIFO_ADMIN_NOTIFY) + "]."); + Log::syserror("Failed to create pipe FIFO [" + std::string(FIFO_ADMIN_NOTIFY) + "]."); exit(Application::EXIT_SOFTWARE); } if ((notifyPipe = open(pipeNotify.c_str(), pipeFlags) ) < 0) { - Log::error("Error: pipe opened for reading."); + Log::syserror("Failed to open pipe for reading."); exit(Application::EXIT_SOFTWARE); } if ((pipeFlags = fcntl(notifyPipe, F_GETFL, 0)) < 0) { - Log::error("Error: failed to get pipe flags [" + std::string(FIFO_ADMIN_NOTIFY) + "]."); + Log::syserror("Failed to get pipe flags [" + std::string(FIFO_ADMIN_NOTIFY) + "]."); exit(Application::EXIT_SOFTWARE); } pipeFlags &= ~O_NONBLOCK; if (fcntl(notifyPipe, F_SETFL, pipeFlags) < 0) { - Log::error("Error: failed to set pipe flags [" + std::string(FIFO_ADMIN_NOTIFY) + "]."); + Log::syserror("Failed to set pipe flags [" + std::string(FIFO_ADMIN_NOTIFY) + "]."); exit(Application::EXIT_SOFTWARE); } @@ -1362,7 +1362,7 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/) if ( (BrokerWritePipe = open(pipeLoolwsd.c_str(), O_WRONLY) ) < 0 ) { - Log::error("Error: failed to open pipe [" + pipeLoolwsd + "] write only."); + Log::syserror("Failed to open pipe [" + pipeLoolwsd + "] for writing."); return Application::EXIT_SOFTWARE; } @@ -1434,7 +1434,7 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/) } else if (pid < 0) { - Log::error("Error: waitpid failed."); + Log::syserror("waitpid failed."); // No child processes if (errno == ECHILD) { commit 5637064e9a82d332f842440b36e36afc639acfc1 Author: Tor Lillqvist <t...@collabora.com> Date: Thu Apr 7 10:55:57 2016 +0300 Factor out the prctl() calls Silly to keep copy-pasting the same couple of lines over and over again. diff --git a/loolwsd/Admin.cpp b/loolwsd/Admin.cpp index 99dbe36..e884550 100644 --- a/loolwsd/Admin.cpp +++ b/loolwsd/Admin.cpp @@ -10,7 +10,6 @@ #include <cassert> #include <mutex> #include <sys/poll.h> -#include <sys/prctl.h> #include <Poco/Net/HTTPCookie.h> #include <Poco/Net/HTTPBasicCredentials.h> @@ -336,8 +335,7 @@ void AdminRequestHandler::handleRequest(HTTPServerRequest& request, HTTPServerRe const auto nSessionId = Util::decodeId(LOOLWSD::GenSessionId()); const std::string thread_name = "admin_ws_" + std::to_string(nSessionId); - if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(thread_name.c_str()), 0, 0, 0) != 0) - Log::syserror("Cannot set thread name to " + thread_name + "."); + Util::setThreadName(thread_name); Log::debug("Thread [" + thread_name + "] started."); @@ -453,8 +451,7 @@ void Admin::run() static const std::string thread_name = "admin_thread"; - if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(thread_name.c_str()), 0, 0, 0) != 0) - Log::syserror("Cannot set thread name to " + thread_name + "."); + Util::setThreadName(thread_name); Log::info("Thread [" + thread_name + "] started."); diff --git a/loolwsd/ChildProcessSession.cpp b/loolwsd/ChildProcessSession.cpp index 0291213..4d46330 100644 --- a/loolwsd/ChildProcessSession.cpp +++ b/loolwsd/ChildProcessSession.cpp @@ -7,8 +7,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include <sys/prctl.h> - #include <iostream> #include <Poco/Exception.h> @@ -202,8 +200,7 @@ public: { static const std::string thread_name = "kit_callback"; - if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(thread_name.c_str()), 0, 0, 0) != 0) - Log::syserror("Cannot set thread name to " + thread_name + "."); + Util::setThreadName(thread_name); Log::debug("Thread [" + thread_name + "] started."); diff --git a/loolwsd/IoUtil.cpp b/loolwsd/IoUtil.cpp index c01770d..7de0230 100644 --- a/loolwsd/IoUtil.cpp +++ b/loolwsd/IoUtil.cpp @@ -8,7 +8,6 @@ */ #include <sys/poll.h> -#include <sys/prctl.h> #include <cassert> #include <cstdlib> diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 3359d66..57862b2 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -14,7 +14,6 @@ #include <dlfcn.h> #include <ftw.h> #include <sys/capability.h> -#include <sys/prctl.h> #include <unistd.h> #include <utime.h> @@ -280,8 +279,7 @@ public: { const std::string thread_name = "kit_ws_" + _session->getId(); - if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(thread_name.c_str()), 0, 0, 0) != 0) - Log::error("Cannot set thread name to " + thread_name + "."); + Util::setThreadName(thread_name); Log::debug("Thread [" + thread_name + "] started."); @@ -898,8 +896,7 @@ void lokit_main(const std::string& childRoot, static const std::string jailId = pid; static const std::string process_name = "loolkit"; - if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(process_name.c_str()), 0, 0, 0) != 0) - Log::error("Cannot set process name to " + process_name + "."); + Util::setThreadName(process_name); Util::setTerminationSignals(); Util::setFatalSignals(); diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index 3642183..688aff1 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -18,7 +18,6 @@ #include <unistd.h> #include <sys/types.h> -#include <sys/prctl.h> #include <sys/stat.h> #include <sys/wait.h> @@ -586,8 +585,7 @@ public: const auto id = LOOLWSD::GenSessionId(); const std::string thread_name = "client_ws_" + id; - if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(thread_name.c_str()), 0, 0, 0) != 0) - Log::syserror("Cannot set thread name to " + thread_name + "."); + Util::setThreadName(thread_name); Log::debug("Thread [" + thread_name + "] started."); @@ -635,8 +633,8 @@ public: void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response) override { std::string thread_name = "prison_ws_"; - if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(thread_name.c_str()), 0, 0, 0) != 0) - Log::syserror("Cannot set thread name to " + thread_name + "."); + + Util::setThreadName(thread_name); Log::debug("Child connection with URI [" + request.getURI() + "]."); @@ -698,9 +696,11 @@ public: } thread_name += sessionId; - if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(thread_name.c_str()), 0, 0, 0) != 0) - Log::syserror("Cannot set thread name to " + thread_name + "."); + Util::setThreadName(thread_name); + + // Misleading debug message, we obviously started already a while ago and have done lots + // of stuff already. Log::debug("Thread [" + thread_name + "] started."); Log::debug("Child socket for SessionId: " + sessionId + ", jailId: " + jailId + @@ -805,8 +805,7 @@ public: HTTPRequestHandler* createRequestHandler(const HTTPServerRequest& request) override { - if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>("request_handler"), 0, 0, 0) != 0) - Log::syserror("Cannot set thread name to request_handler."); + Util::setThreadName("request_handler"); auto logger = Log::info(); logger << "Request from " << request.clientAddress().toString() << ": " @@ -855,8 +854,7 @@ class PrisonerRequestHandlerFactory: public HTTPRequestHandlerFactory public: HTTPRequestHandler* createRequestHandler(const HTTPServerRequest& request) override { - if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>("request_handler"), 0, 0, 0) != 0) - Log::syserror("Cannot set thread name to request_handler."); + Util::setThreadName("request_handler"); auto logger = Log::info(); logger << "Request from " << request.clientAddress().toString() << ": " diff --git a/loolwsd/QueueHandler.hpp b/loolwsd/QueueHandler.hpp index 1c46ce6..471c5b3 100644 --- a/loolwsd/QueueHandler.hpp +++ b/loolwsd/QueueHandler.hpp @@ -29,8 +29,7 @@ public: void run() override { - if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(_name.c_str()), 0, 0, 0) != 0) - Log::syserror("Cannot set thread name to " + _name + "."); + Util::setThreadName(_name); Log::debug("Thread [" + _name + "] started."); diff --git a/loolwsd/Util.cpp b/loolwsd/Util.cpp index 8056497..c58202b 100644 --- a/loolwsd/Util.cpp +++ b/loolwsd/Util.cpp @@ -533,6 +533,12 @@ namespace Util r = s; return replace(r, "\n", " / "); } + + void setThreadName(const std::string& s) + { + if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(s.c_str()), 0, 0, 0) != 0) + Log::syserror("Cannot set thread name to " + s + "."); + } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/loolwsd/Util.hpp b/loolwsd/Util.hpp index 9380f49..008d02a 100644 --- a/loolwsd/Util.hpp +++ b/loolwsd/Util.hpp @@ -131,6 +131,8 @@ namespace Util std::string replace(const std::string& s, const std::string& a, const std::string& b); std::string formatLinesForLog(const std::string& s); + + void setThreadName(const std::string& s); }; //TODO: Move to own file. commit ec604599f18a989d705881ae65844679a06fa2af Author: Tor Lillqvist <t...@collabora.com> Date: Thu Apr 7 10:36:38 2016 +0300 Introduce separate Log::syserror() function for logging actual syscall errors Much better than assuming that errno would be relevant at all Log::error() calls (or alternatively, having to remember to append a false parameter to the Log::error() call, which had not been done a single time anyway.) Call log::syserror() right after a system call has returned an error. Don't call it otherwise. diff --git a/loolwsd/Admin.cpp b/loolwsd/Admin.cpp index 83d0312..99dbe36 100644 --- a/loolwsd/Admin.cpp +++ b/loolwsd/Admin.cpp @@ -337,7 +337,7 @@ void AdminRequestHandler::handleRequest(HTTPServerRequest& request, HTTPServerRe const std::string thread_name = "admin_ws_" + std::to_string(nSessionId); if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(thread_name.c_str()), 0, 0, 0) != 0) - Log::error("Cannot set thread name to " + thread_name + "."); + Log::syserror("Cannot set thread name to " + thread_name + "."); Log::debug("Thread [" + thread_name + "] started."); @@ -454,7 +454,7 @@ void Admin::run() static const std::string thread_name = "admin_thread"; if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(thread_name.c_str()), 0, 0, 0) != 0) - Log::error("Cannot set thread name to " + thread_name + "."); + Log::syserror("Cannot set thread name to " + thread_name + "."); Log::info("Thread [" + thread_name + "] started."); diff --git a/loolwsd/ChildProcessSession.cpp b/loolwsd/ChildProcessSession.cpp index 385c880..0291213 100644 --- a/loolwsd/ChildProcessSession.cpp +++ b/loolwsd/ChildProcessSession.cpp @@ -203,7 +203,7 @@ public: static const std::string thread_name = "kit_callback"; if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(thread_name.c_str()), 0, 0, 0) != 0) - Log::error("Cannot set thread name to " + thread_name + "."); + Log::syserror("Cannot set thread name to " + thread_name + "."); Log::debug("Thread [" + thread_name + "] started."); diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp index 6ca9906..7dedb64 100644 --- a/loolwsd/DocumentBroker.hpp +++ b/loolwsd/DocumentBroker.hpp @@ -81,7 +81,7 @@ public: { if (rude && kill(_pid, SIGINT) != 0 && kill(_pid, 0) != 0) { - Log::error("Cannot terminate lokit [" + std::to_string(_pid) + "]. Abandoning."); + Log::syserror("Cannot terminate lokit [" + std::to_string(_pid) + "]. Abandoning."); } _pid = -1; diff --git a/loolwsd/IoUtil.cpp b/loolwsd/IoUtil.cpp index 36d5d90..c01770d 100644 --- a/loolwsd/IoUtil.cpp +++ b/loolwsd/IoUtil.cpp @@ -219,10 +219,10 @@ ssize_t writeFIFO(int pipe, const char* buffer, ssize_t size) const auto bytes = write(pipe, buffer + count, size - count); if (bytes < 0) { - Log::error("Failed to write to pipe. Retrying. Data: [" + std::string(buffer, size) + "]."); if (errno == EINTR || errno == EAGAIN) continue; + Log::syserror("Failed to write to pipe. Data: [" + std::string(buffer, size) + "]."); count = -1; break; } diff --git a/loolwsd/LOOLForKit.cpp b/loolwsd/LOOLForKit.cpp index e762d77..495a1ce 100644 --- a/loolwsd/LOOLForKit.cpp +++ b/loolwsd/LOOLForKit.cpp @@ -112,7 +112,10 @@ static int createLibreOfficeKit(const std::string& childRoot, { // parent childPID = pid; // (somehow - switch the hash to use real pids or ?) ... - Log::info("Forked kit [" + std::to_string(childPID) + "]."); + if (pid < 0) + Log::syserror("Fork failed."); + else + Log::info("Forked kit [" + std::to_string(childPID) + "]."); } Log::info() << "Created Kit #" << ChildCounter << ", PID: " << childPID << Log::end; @@ -154,7 +157,7 @@ int main(int argc, char** argv) // Auto-reap zombies. if (signal(SIGCHLD, SIG_IGN) == SIG_ERR) { - Log::error("Failed to set SIGCHLD to SIG_IGN."); + Log::syserror("Failed to set SIGCHLD to SIG_IGN."); return 1; } @@ -211,7 +214,7 @@ int main(int argc, char** argv) 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 [" + pipeLoolwsd + "] read only. Exiting."); + Log::syserror("Error: failed to open pipe [" + pipeLoolwsd + "] read only. Exiting."); std::exit(Application::EXIT_SOFTWARE); } @@ -224,7 +227,7 @@ int main(int argc, char** argv) // We must have at least one child, more are created dynamically. if (createLibreOfficeKit(childRoot, sysTemplate, loTemplate, loSubPath) < 0) { - Log::error("Error: failed to create children."); + Log::error("Error: failed to create a kit process."); std::exit(Application::EXIT_SOFTWARE); } @@ -251,7 +254,7 @@ int main(int argc, char** argv) { if (createLibreOfficeKit(childRoot, sysTemplate, loTemplate, loSubPath) < 0) { - Log::error("Error: fork failed."); + Log::error("Error: failed to create a kit process."); } else { diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index 47c3d62..3642183 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -175,7 +175,7 @@ std::shared_ptr<ChildProcess> getNewChild() int balance = LOOLWSD::NumPreSpawnedChildren; if (available == 0) { - Log::error("No available child. Sending spawn request to Broker and failing."); + Log::error("No available child. Sending spawn request to forkit and failing."); } else { @@ -587,7 +587,7 @@ public: const std::string thread_name = "client_ws_" + id; if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(thread_name.c_str()), 0, 0, 0) != 0) - Log::error("Cannot set thread name to " + thread_name + "."); + Log::syserror("Cannot set thread name to " + thread_name + "."); Log::debug("Thread [" + thread_name + "] started."); @@ -636,7 +636,7 @@ public: { std::string thread_name = "prison_ws_"; if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(thread_name.c_str()), 0, 0, 0) != 0) - Log::error("Cannot set thread name to " + thread_name + "."); + Log::syserror("Cannot set thread name to " + thread_name + "."); Log::debug("Child connection with URI [" + request.getURI() + "]."); @@ -699,7 +699,7 @@ public: thread_name += sessionId; if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(thread_name.c_str()), 0, 0, 0) != 0) - Log::error("Cannot set thread name to " + thread_name + "."); + Log::syserror("Cannot set thread name to " + thread_name + "."); Log::debug("Thread [" + thread_name + "] started."); @@ -806,7 +806,7 @@ public: HTTPRequestHandler* createRequestHandler(const HTTPServerRequest& request) override { if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>("request_handler"), 0, 0, 0) != 0) - Log::error("Cannot set thread name to request_handler."); + Log::syserror("Cannot set thread name to request_handler."); auto logger = Log::info(); logger << "Request from " << request.clientAddress().toString() << ": " @@ -856,7 +856,7 @@ public: HTTPRequestHandler* createRequestHandler(const HTTPServerRequest& request) override { if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>("request_handler"), 0, 0, 0) != 0) - Log::error("Cannot set thread name to request_handler."); + Log::syserror("Cannot set thread name to request_handler."); auto logger = Log::info(); logger << "Request from " << request.clientAddress().toString() << ": " @@ -902,7 +902,7 @@ public: } catch (const WebSocketException& exc) { - Log::error("TestOutput::run(), WebSocketException: " + exc.message()); + Log::error("TestOutput::run: WebSocketException: " + exc.message()); _ws.close(); } } @@ -1245,8 +1245,8 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/) if (access(Cache.c_str(), R_OK | W_OK | X_OK) != 0) { - Log::error("Unable to access cache [" + Cache + - "] please make sure it exists, and has write permission for this user."); + Log::syserror("Unable to access cache [" + Cache + + "] please make sure it exists, and has write permission for this user."); return Application::EXIT_SOFTWARE; } @@ -1300,7 +1300,7 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/) const std::string pipeNotify = Path(pipePath, FIFO_ADMIN_NOTIFY).toString(); if (mkfifo(pipeNotify.c_str(), 0666) < 0 && errno != EEXIST) { - Log::error("Error: Failed to create pipe FIFO [" + std::string(FIFO_ADMIN_NOTIFY) + "]."); + Log::syserror("Error: Failed to create pipe FIFO [" + std::string(FIFO_ADMIN_NOTIFY) + "]."); exit(Application::EXIT_SOFTWARE); } diff --git a/loolwsd/QueueHandler.hpp b/loolwsd/QueueHandler.hpp index dbe7ac1..1c46ce6 100644 --- a/loolwsd/QueueHandler.hpp +++ b/loolwsd/QueueHandler.hpp @@ -30,7 +30,7 @@ public: void run() override { if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(_name.c_str()), 0, 0, 0) != 0) - Log::error("Cannot set thread name to " + _name + "."); + Log::syserror("Cannot set thread name to " + _name + "."); Log::debug("Thread [" + _name + "] started."); diff --git a/loolwsd/Util.cpp b/loolwsd/Util.cpp index 0bf930e..8056497 100644 --- a/loolwsd/Util.cpp +++ b/loolwsd/Util.cpp @@ -172,12 +172,15 @@ namespace Log logger().warning(logPrefix() + msg); } - void error(const std::string& msg, const bool append_errno) + void error(const std::string& msg) { - logger().error(logPrefix() + msg + - (append_errno - ? (std::string(" (errno: ") + strerror(errno) + ").") - : std::string(""))); + logger().error(logPrefix() + msg); + } + + void syserror(const std::string& msg) + { + logger().error(logPrefix() + msg + " (errno: " + std::string(std::strerror(errno)) + ")"); + } } diff --git a/loolwsd/Util.hpp b/loolwsd/Util.hpp index 01c6c45..9380f49 100644 --- a/loolwsd/Util.hpp +++ b/loolwsd/Util.hpp @@ -143,7 +143,8 @@ namespace Log void debug(const std::string& msg); void info(const std::string& msg); void warn(const std::string& msg); - void error(const std::string& msg, const bool append_errno = true); + void error(const std::string& msg); + void syserror(const std::string& msg); /// The following is to write streaming logs. /// Log::info() << "Value: 0x" << std::hex << value commit 94caec287f7df58786ea68e9eb0edbbb6a1e4471 Author: Tor Lillqvist <t...@collabora.com> Date: Thu Apr 7 10:15:51 2016 +0300 We never call Log::warn() with an append_errno parameter So just drop it. Default parameters are ugly IMHO. diff --git a/loolwsd/Util.cpp b/loolwsd/Util.cpp index caeab08..0bf930e 100644 --- a/loolwsd/Util.cpp +++ b/loolwsd/Util.cpp @@ -167,12 +167,9 @@ namespace Log logger().information(logPrefix() + msg); } - void warn(const std::string& msg, const bool append_errno) + void warn(const std::string& msg) { - logger().warning(logPrefix() + msg + - (append_errno - ? (std::string(" (errno: ") + strerror(errno) + ").") - : std::string(""))); + logger().warning(logPrefix() + msg); } void error(const std::string& msg, const bool append_errno) diff --git a/loolwsd/Util.hpp b/loolwsd/Util.hpp index 517724d..01c6c45 100644 --- a/loolwsd/Util.hpp +++ b/loolwsd/Util.hpp @@ -142,7 +142,7 @@ namespace Log void trace(const std::string& msg); void debug(const std::string& msg); void info(const std::string& msg); - void warn(const std::string& msg, const bool append_errno = false); + void warn(const std::string& msg); void error(const std::string& msg, const bool append_errno = true); /// The following is to write streaming logs. commit 62296486104f4d373c89e9c5559d3ea221b1a177 Author: Tor Lillqvist <t...@collabora.com> Date: Thu Apr 7 10:13:56 2016 +0300 Include dlerror() message in log output also if dlsym() fails diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 468915c..3359d66 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -1126,7 +1126,7 @@ bool globalPreinit(const std::string &loTemplate) LokHookPreInit* preInit = (LokHookPreInit *)dlsym(handle, "lok_preinit"); if (!preInit) { - Log::error("No lok_preinit symbol in " + loadedLibrary); + Log::error("No lok_preinit symbol in " + loadedLibrary + ": " + std::string(dlerror())); return false; } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits