[Libreoffice-commits] online.git: 2 commits - common/Unit.cpp common/Unit.hpp kit/ForKit.cpp kit/Kit.cpp test/UnitTimeout.cpp tools/Config.cpp tools/Connect.cpp tools/KitClient.cpp tools/map.cpp tools/Stress.cpp tools/Tool.cpp wsd/LOOLWSD.cpp
Jan Holesovsky (via logerrit)
logerrit at kemper.freedesktop.org
Thu Nov 7 11:24:06 UTC 2019
common/Unit.cpp | 38 ++++++++++++++++++++++++--------------
common/Unit.hpp | 1 -
kit/ForKit.cpp | 19 ++++++++-----------
kit/Kit.cpp | 25 ++++++++++++-------------
test/UnitTimeout.cpp | 9 ++++-----
tools/Config.cpp | 11 ++++++-----
tools/Connect.cpp | 7 ++++---
tools/KitClient.cpp | 9 +++++----
tools/Stress.cpp | 7 ++++---
tools/Tool.cpp | 7 ++++---
tools/map.cpp | 1 +
wsd/LOOLWSD.cpp | 13 +++++++------
12 files changed, 79 insertions(+), 68 deletions(-)
New commits:
commit f0ea9701d8ba1339f9091b08602d3e973710ff28
Author: Jan Holesovsky <kendy at collabora.com>
AuthorDate: Wed Nov 6 14:03:53 2019 +0100
Commit: Jan Holesovsky <kendy at collabora.com>
CommitDate: Thu Nov 7 12:24:01 2019 +0100
killpoco: Use std::thread instead of Poco::Thread.
Change-Id: I533429412f269cff8714407f3b99aef0ff133abf
Reviewed-on: https://gerrit.libreoffice.org/82199
Reviewed-by: Jan Holesovsky <kendy at collabora.com>
Tested-by: Jan Holesovsky <kendy at collabora.com>
diff --git a/common/Unit.cpp b/common/Unit.cpp
index 8682aa45d..5dc01d4ea 100644
--- a/common/Unit.cpp
+++ b/common/Unit.cpp
@@ -16,8 +16,8 @@
#include <dlfcn.h>
#include <fstream>
#include <sysexits.h>
+#include <thread>
-#include <Poco/Thread.h>
#include <Poco/Util/LayeredConfiguration.h>
#include "Log.hpp"
@@ -27,7 +27,9 @@
UnitBase *UnitBase::Global = nullptr;
-static Poco::Thread TimeoutThread("unit timeout");
+static std::thread TimeoutThread;
+static std::atomic<bool> TimeoutThreadRunning(false);
+std::timed_mutex TimeoutThreadMutex;
UnitBase *UnitBase::linkAndCreateUnit(UnitType type, const std::string &unitLibPath)
{
@@ -82,13 +84,22 @@ bool UnitBase::init(UnitType type, const std::string &unitLibPath)
Global = linkAndCreateUnit(type, unitLibPath);
if (Global && type == UnitType::Kit)
{
- TimeoutThread.startFunc([](){
- Poco::Thread::trySleep(Global->_timeoutMilliSeconds);
- if (!Global->_timeoutShutdown)
+ TimeoutThreadMutex.lock();
+ TimeoutThread = std::thread([]{
+ TimeoutThreadRunning = true;
+ Util::setThreadName("unit timeout");
+
+ if (TimeoutThreadMutex.try_lock_for(std::chrono::milliseconds(Global->_timeoutMilliSeconds)))
+ {
+ LOG_DBG("Unit test finished in time");
+ TimeoutThreadMutex.unlock();
+ }
+ else
{
LOG_ERR("Unit test timeout");
Global->timeout();
}
+ TimeoutThreadRunning = false;
});
}
}
@@ -121,7 +132,7 @@ bool UnitBase::isUnitTesting()
void UnitBase::setTimeout(int timeoutMilliSeconds)
{
- assert(!TimeoutThread.isRunning());
+ assert(!TimeoutThreadRunning);
_timeoutMilliSeconds = timeoutMilliSeconds;
}
@@ -130,7 +141,6 @@ UnitBase::UnitBase()
_setRetValue(false),
_retValue(0),
_timeoutMilliSeconds(30 * 1000),
- _timeoutShutdown(false),
_type(UnitType::Wsd)
{
}
@@ -206,9 +216,10 @@ void UnitBase::returnValue(int &retValue)
if (_setRetValue)
retValue = _retValue;
- _timeoutShutdown = true;
- TimeoutThread.wakeUp();
- TimeoutThread.join();
+ // tell the timeout thread that the work has finished
+ TimeoutThreadMutex.unlock();
+ if (TimeoutThread.joinable())
+ TimeoutThread.join();
delete Global;
Global = nullptr;
diff --git a/common/Unit.hpp b/common/Unit.hpp
index 57d7916bf..63975514b 100644
--- a/common/Unit.hpp
+++ b/common/Unit.hpp
@@ -146,7 +146,6 @@ private:
bool _setRetValue;
int _retValue;
int _timeoutMilliSeconds;
- std::atomic<bool> _timeoutShutdown;
static UnitBase *Global;
UnitType _type;
};
commit 5b5e29b4303ffff0b8e2fc91bcccd772a42a78f7
Author: Jan Holesovsky <kendy at collabora.com>
AuthorDate: Wed Nov 6 10:07:32 2019 +0100
Commit: Jan Holesovsky <kendy at collabora.com>
CommitDate: Thu Nov 7 12:23:47 2019 +0100
killpoco: Don't use POCO for app exit values.
Change-Id: I2948ac45a7b4243f7afde08d5245530fdbf9a070
Reviewed-on: https://gerrit.libreoffice.org/82125
Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
Tested-by: Michael Meeks <michael.meeks at collabora.com>
Reviewed-by: Jan Holesovsky <kendy at collabora.com>
diff --git a/common/Unit.cpp b/common/Unit.cpp
index 151a4505d..8682aa45d 100644
--- a/common/Unit.cpp
+++ b/common/Unit.cpp
@@ -15,9 +15,10 @@
#include <cassert>
#include <dlfcn.h>
#include <fstream>
+#include <sysexits.h>
#include <Poco/Thread.h>
-#include <Poco/Util/Application.h>
+#include <Poco/Util/LayeredConfiguration.h>
#include "Log.hpp"
#include "Util.hpp"
@@ -186,9 +187,7 @@ void UnitBase::exitTest(TestResult result)
{
LOG_INF("exitTest: " << (int)result << ". Flagging for termination.");
_setRetValue = true;
- _retValue = result == TestResult::Ok ?
- Poco::Util::Application::EXIT_OK :
- Poco::Util::Application::EXIT_SOFTWARE;
+ _retValue = result == TestResult::Ok ? EX_OK : EX_SOFTWARE;
SigUtil::setTerminationFlag();
SocketPoll::wakeupWorld();
}
diff --git a/kit/ForKit.cpp b/kit/ForKit.cpp
index c6e2ebd4a..7150ee6ab 100644
--- a/kit/ForKit.cpp
+++ b/kit/ForKit.cpp
@@ -17,6 +17,7 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
+#include <sysexits.h>
#include <atomic>
#include <cstdlib>
@@ -27,7 +28,6 @@
#include <Poco/Path.h>
#include <Poco/Process.h>
#include <Poco/Thread.h>
-#include <Poco/Util/Application.h>
#include <Common.hpp>
#include <IoUtil.hpp>
@@ -43,9 +43,6 @@
using Poco::Process;
using Poco::Thread;
-#ifndef KIT_IN_PROCESS
-using Poco::Util::Application;
-#endif
#ifndef KIT_IN_PROCESS
static bool NoCapsForKit = false;
@@ -353,7 +350,7 @@ int main(int argc, char** argv)
{
if (!hasCorrectUID("loolforkit"))
{
- return Application::EXIT_SOFTWARE;
+ return EX_SOFTWARE;
}
if (std::getenv("SLEEPFORDEBUGGER"))
@@ -490,14 +487,14 @@ int main(int argc, char** argv)
loTemplate.empty() || childRoot.empty())
{
printArgumentHelp();
- return Application::EXIT_USAGE;
+ return EX_USAGE;
}
if (!UnitBase::init(UnitBase::UnitType::Kit,
UnitTestLibrary))
{
LOG_ERR("Failed to load kit unit test library");
- return Application::EXIT_USAGE;
+ return EX_USAGE;
}
// Setup & check environment
@@ -528,7 +525,7 @@ int main(int argc, char** argv)
std::cerr << "FATAL: Capabilities are not set for the loolforkit program." << std::endl;
std::cerr << "Please make sure that the current partition was *not* mounted with the 'nosuid' option." << std::endl;
std::cerr << "If you are on SLES11, please set 'file_caps=1' as kernel boot option." << std::endl << std::endl;
- return Application::EXIT_SOFTWARE;
+ return EX_SOFTWARE;
}
// Set various options we need.
@@ -542,7 +539,7 @@ int main(int argc, char** argv)
{
LOG_FTL("Failed to preinit lokit.");
Log::shutdown();
- std::_Exit(Application::EXIT_SOFTWARE);
+ std::_Exit(EX_SOFTWARE);
}
if (Util::getProcessThreadCount() != 1)
@@ -558,7 +555,7 @@ int main(int argc, char** argv)
{
LOG_FTL("Failed to create a kit process.");
Log::shutdown();
- std::_Exit(Application::EXIT_SOFTWARE);
+ std::_Exit(EX_SOFTWARE);
}
// No need to trace subsequent children.
@@ -585,7 +582,7 @@ int main(int argc, char** argv)
forkLibreOfficeKit(childRoot, sysTemplate, loTemplate, loSubPath);
}
- int returnValue = Application::EXIT_OK;
+ int returnValue = EX_OK;
UnitKit::get().returnValue(returnValue);
#if 0
diff --git a/kit/Kit.cpp b/kit/Kit.cpp
index 6ae7e0eec..cd397d397 100644
--- a/kit/Kit.cpp
+++ b/kit/Kit.cpp
@@ -23,6 +23,7 @@
#include <utime.h>
#include <sys/time.h>
#include <sys/resource.h>
+#include <sysexits.h>
#include <atomic>
#include <cassert>
@@ -52,7 +53,6 @@
#include <Poco/StringTokenizer.h>
#include <Poco/Thread.h>
#include <Poco/URI.h>
-#include <Poco/Util/Application.h>
#include "ChildSession.hpp"
#include <Common.hpp>
@@ -99,7 +99,6 @@ using Poco::JSON::Parser;
using Poco::StringTokenizer;
using Poco::Thread;
using Poco::URI;
-using Poco::Util::Application;
#ifndef BUILDING_TESTS
using Poco::Path;
@@ -224,7 +223,7 @@ namespace
LOG_FTL("Copying of '" << fpath << "' to " << newPath.toString() <<
" failed: " << exc.what() << ". Exiting.");
Log::shutdown();
- std::_Exit(Application::EXIT_SOFTWARE);
+ std::_Exit(EX_SOFTWARE);
}
}
}
@@ -841,7 +840,7 @@ public:
{
LOG_FTL("Document [" << anonymizeUrl(_url) << "] has no more views, exiting bluntly.");
Log::shutdown();
- std::_Exit(Application::EXIT_OK);
+ std::_Exit(EX_OK);
}
#endif
}
@@ -1386,7 +1385,7 @@ private:
{
LOG_INF("Document [" << anonymizeUrl(_url) << "] has no more views, exiting bluntly.");
Log::shutdown();
- std::_Exit(Application::EXIT_OK);
+ std::_Exit(EX_OK);
}
#endif
LOG_INF("Document [" << anonymizeUrl(_url) << "] has no more views, but has " <<
@@ -1976,7 +1975,7 @@ public:
LOG_FTL("QueueHandler::run: Exception: " << exc.what());
#if !MOBILEAPP
Log::shutdown();
- std::_Exit(Application::EXIT_SOFTWARE);
+ std::_Exit(EX_SOFTWARE);
#endif
}
catch (...)
@@ -1984,7 +1983,7 @@ public:
LOG_FTL("QueueHandler::run: Unknown exception");
#if !MOBILEAPP
Log::shutdown();
- std::_Exit(Application::EXIT_SOFTWARE);
+ std::_Exit(EX_SOFTWARE);
#endif
}
}
@@ -2456,14 +2455,14 @@ void lokit_main(
{
LOG_SFL("chroot(\"" << jailPath.toString() << "\") failed.");
Log::shutdown();
- std::_Exit(Application::EXIT_SOFTWARE);
+ std::_Exit(EX_SOFTWARE);
}
if (chdir("/") == -1)
{
LOG_SFL("chdir(\"/\") in jail failed.");
Log::shutdown();
- std::_Exit(Application::EXIT_SOFTWARE);
+ std::_Exit(EX_SOFTWARE);
}
dropCapability(CAP_SYS_CHROOT);
@@ -2506,7 +2505,7 @@ void lokit_main(
{
LOG_FTL("LibreOfficeKit initialization failed. Exiting.");
Log::shutdown();
- std::_Exit(Application::EXIT_SOFTWARE);
+ std::_Exit(EX_SOFTWARE);
}
}
@@ -2517,7 +2516,7 @@ void lokit_main(
{
LOG_FTL("LibreOfficeKit seccomp security lockdown failed. Exiting.");
Log::shutdown();
- std::_Exit(Application::EXIT_SOFTWARE);
+ std::_Exit(EX_SOFTWARE);
}
LOG_ERR("LibreOfficeKit seccomp security lockdown failed, but configured to continue. "
@@ -2615,7 +2614,7 @@ void lokit_main(
{
LOG_ERR("Kit is missing Unipoll API");
std::cout << "Fatal: out of date LibreOfficeKit - no Unipoll API\n";
- std::_Exit(Application::EXIT_SOFTWARE);
+ std::_Exit(EX_SOFTWARE);
}
LOG_INF("Kit unipoll loop run");
@@ -2652,7 +2651,7 @@ void lokit_main(
LOG_INF("Process finished.");
Log::shutdown();
std::unique_lock<std::mutex> lock(SigUtil::getSigHandlerTrap());
- std::_Exit(Application::EXIT_OK);
+ std::_Exit(EX_OK);
#endif
}
diff --git a/test/UnitTimeout.cpp b/test/UnitTimeout.cpp
index fc9881285..d0b2de79c 100644
--- a/test/UnitTimeout.cpp
+++ b/test/UnitTimeout.cpp
@@ -10,8 +10,7 @@
#include <config.h>
#include <cassert>
-
-#include <Poco/Util/Application.h>
+#include <sysexits.h>
#include <Log.hpp>
#include <Util.hpp>
@@ -36,14 +35,14 @@ public:
if (!_timedOut)
{
LOG_INF("Failed to timeout");
- retValue = Poco::Util::Application::EXIT_SOFTWARE;
+ retValue = EX_SOFTWARE;
}
else
{
assert(_setRetValue);
- assert(_retValue == Poco::Util::Application::EXIT_SOFTWARE);
+ assert(_retValue == EX_SOFTWARE);
// we wanted a timeout.
- retValue = Poco::Util::Application::EXIT_OK;
+ retValue = EX_OK;
}
}
diff --git a/tools/Config.cpp b/tools/Config.cpp
index 2cf45ac3f..754062a4e 100644
--- a/tools/Config.cpp
+++ b/tools/Config.cpp
@@ -12,6 +12,7 @@
#include <iostream>
#include <iomanip>
#include <sstream>
+#include <sysexits.h>
#include <termios.h>
#include <openssl/rand.h>
@@ -164,7 +165,7 @@ void Config::handleOption(const std::string& optionName, const std::string& opti
if (optionName == "help")
{
displayHelp();
- std::exit(Application::EXIT_OK);
+ std::exit(EX_OK);
}
else if (optionName == "config-file")
{
@@ -219,10 +220,10 @@ int Config::main(const std::vector<std::string>& args)
{
std::cerr << "Nothing to do." << std::endl;
displayHelp();
- return Application::EXIT_NOINPUT;
+ return EX_NOINPUT;
}
- int retval = Application::EXIT_OK;
+ int retval = EX_OK;
bool changed = false;
_loolConfig.load(ConfigFile);
@@ -262,7 +263,7 @@ int Config::main(const std::vector<std::string>& args)
if (adminPwd != reAdminPwd)
{
std::cout << "Password mismatch." << std::endl;
- return Application::EXIT_DATAERR;
+ return EX_DATAERR;
}
// Do the magic !
@@ -297,7 +298,7 @@ int Config::main(const std::vector<std::string>& args)
changed = true;
#else
std::cerr << "This application was compiled with old OpenSSL. Operation not supported. You can use plain text password in /etc/loolwsd/loolwsd.xml." << std::endl;
- return Application::EXIT_UNAVAILABLE;
+ return EX_UNAVAILABLE;
#endif
}
#if ENABLE_SUPPORT_KEY
diff --git a/tools/Connect.cpp b/tools/Connect.cpp
index 985ce681b..146d98294 100644
--- a/tools/Connect.cpp
+++ b/tools/Connect.cpp
@@ -14,6 +14,7 @@
#include <fstream>
#include <iostream>
#include <mutex>
+#include <sysexits.h>
#include <thread>
#include <Poco/Net/AcceptCertificateHandler.h>
@@ -114,7 +115,7 @@ public:
std::cout << "CLOSE frame received" << std::endl;
}
if (!closeExpected)
- std::_Exit(Application::EXIT_SOFTWARE);
+ std::_Exit(EX_SOFTWARE);
}
catch (WebSocketException& exc)
{
@@ -146,7 +147,7 @@ protected:
if (args.size() < 1)
{
LOG_ERR("Usage: connect documentURI [serverURI]");
- return Application::EXIT_USAGE;
+ return EX_USAGE;
}
if (args.size() > 1)
@@ -228,7 +229,7 @@ protected:
ws.shutdown();
thread.join();
- return Application::EXIT_OK;
+ return EX_OK;
}
private:
diff --git a/tools/KitClient.cpp b/tools/KitClient.cpp
index fdb4ffa84..a869a86f0 100644
--- a/tools/KitClient.cpp
+++ b/tools/KitClient.cpp
@@ -15,6 +15,7 @@
#include <fstream>
#include <iostream>
#include <memory>
+#include <sysexits.h>
#define LOK_USE_UNSTABLE_API
#include <LibreOfficeKit/LibreOfficeKitInit.h>
@@ -54,7 +55,7 @@ protected:
if (args.size() != 2)
{
logger().fatal("Usage: lokitclient /path/to/lo/installation/program /path/to/document");
- return Application::EXIT_USAGE;
+ return EX_USAGE;
}
LibreOfficeKit *loKit;
@@ -64,7 +65,7 @@ protected:
if (!loKit)
{
logger().fatal("LibreOfficeKit initialisation failed");
- return Application::EXIT_UNAVAILABLE;
+ return EX_UNAVAILABLE;
}
@@ -72,7 +73,7 @@ protected:
if (!loKitDocument)
{
logger().fatal("Document loading failed: " + std::string(loKit->pClass->getError(loKit)));
- return Application::EXIT_UNAVAILABLE;
+ return EX_UNAVAILABLE;
}
loKitDocument->pClass->registerCallback(loKitDocument, myCallback, nullptr);
@@ -162,7 +163,7 @@ protected:
}
// Safest to just bluntly exit
- std::_Exit(Application::EXIT_OK);
+ std::_Exit(EX_OK);
}
};
diff --git a/tools/Stress.cpp b/tools/Stress.cpp
index 76e887602..1a4d17124 100644
--- a/tools/Stress.cpp
+++ b/tools/Stress.cpp
@@ -18,6 +18,7 @@
#include <fstream>
#include <iostream>
#include <numeric>
+#include <sysexits.h>
#include <thread>
#include <Poco/Net/HTTPRequest.h>
@@ -258,7 +259,7 @@ void Stress::handleOption(const std::string& optionName,
helpFormatter.setUsage("OPTIONS");
helpFormatter.setHeader("LibreOffice Online tool.");
helpFormatter.format(std::cerr);
- std::exit(Application::EXIT_OK);
+ std::exit(EX_OK);
}
else if (optionName == "bench")
Stress::Benchmark = true;
@@ -286,7 +287,7 @@ int Stress::main(const std::vector<std::string>& args)
std::cerr << "Usage: loolstress [--bench] <tracefile | url> " << std::endl;
std::cerr << " Trace files may be plain text or gzipped (with .gz extension)." << std::endl;
std::cerr << " --help for full arguments list." << std::endl;
- return Application::EXIT_NOINPUT;
+ return EX_NOINPUT;
}
std::vector<std::shared_ptr<Worker>> workers;
@@ -347,7 +348,7 @@ int Stress::main(const std::vector<std::string>& args)
}
}
- return Application::EXIT_OK;
+ return EX_OK;
}
POCO_APP_MAIN(Stress)
diff --git a/tools/Tool.cpp b/tools/Tool.cpp
index 8957f6acc..91fe4600a 100644
--- a/tools/Tool.cpp
+++ b/tools/Tool.cpp
@@ -16,6 +16,7 @@
#include <cstring>
#include <fstream>
#include <iostream>
+#include <sysexits.h>
#include <Poco/Net/HTMLForm.h>
#include <Poco/Net/HTTPClientSession.h>
@@ -179,7 +180,7 @@ void Tool::handleOption(const std::string& optionName,
if (optionName == "help")
{
displayHelp();
- std::exit(Application::EXIT_OK);
+ std::exit(EX_OK);
}
else if (optionName == "extension"
|| optionName == "convert-to")
@@ -246,7 +247,7 @@ int Tool::main(const std::vector<std::string>& origArgs)
{
std::cerr << "Nothing to do." << std::endl;
displayHelp();
- return Application::EXIT_NOINPUT;
+ return EX_NOINPUT;
}
std::vector<std::unique_ptr<Thread>> clients(_numWorkers);
@@ -271,7 +272,7 @@ int Tool::main(const std::vector<std::string>& origArgs)
clients[i]->join();
}
- return Application::EXIT_OK;
+ return EX_OK;
}
POCO_APP_MAIN(Tool)
diff --git a/tools/map.cpp b/tools/map.cpp
index 845adfa07..d2ebb5d6e 100644
--- a/tools/map.cpp
+++ b/tools/map.cpp
@@ -12,6 +12,7 @@
#include <vector>
#include <iostream>
#include <sstream>
+#include <sysexits.h>
#include <unordered_map>
#include <unordered_set>
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index b8b826568..ac42e490a 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -33,6 +33,7 @@
// number of child processes, each which handles a viewing (editing) session for one document.
#include <unistd.h>
+#include <sysexits.h>
#include <sys/stat.h>
#include <sys/types.h>
@@ -999,7 +1000,7 @@ void LOOLWSD::initialize(Application& self)
"'--o:logging.level=trace' from the command line in Makefile.am.\n" << std::endl;
#endif
Log::shutdown();
- _exit(Application::EXIT_SOFTWARE);
+ _exit(EX_SOFTWARE);
}
}
@@ -1373,7 +1374,7 @@ void LOOLWSD::handleOption(const std::string& optionName,
if (optionName == "help")
{
displayHelp();
- std::exit(Application::EXIT_OK);
+ std::exit(EX_OK);
}
else if (optionName == "version")
DisplayVersion = true;
@@ -3246,7 +3247,7 @@ private:
{
LOG_FTL("Failed to create local unix domain socket. Exiting.");
Log::shutdown();
- _exit(Application::EXIT_SOFTWARE);
+ _exit(EX_SOFTWARE);
return nullptr;
}
@@ -3254,7 +3255,7 @@ private:
{
LOG_FTL("Failed to listen on local unix domain socket at " << location << ". Exiting.");
Log::shutdown();
- _exit(Application::EXIT_SOFTWARE);
+ _exit(EX_SOFTWARE);
}
LOG_INF("Listening to prisoner connections on " << location);
@@ -3298,7 +3299,7 @@ private:
{
LOG_FTL("Failed to listen on Server port(s) (" <<
ClientPortNumber << '-' << port << "). Exiting.");
- _exit(Application::EXIT_SOFTWARE);
+ _exit(EX_SOFTWARE);
}
ClientPortNumber = port;
@@ -3592,7 +3593,7 @@ int LOOLWSD::innerMain()
}
#endif // !MOBILEAPP
- return Application::EXIT_OK;
+ return EX_OK;
}
void LOOLWSD::cleanup()
More information about the Libreoffice-commits
mailing list