Skip to content

Commit f81ab4a

Browse files
committed
wsd: clean up the coolwsd process cleanup
Change-Id: Id1266613699f80350cc9a2098e63b3e76eca7ad7 Signed-off-by: Ashod Nakashian <[email protected]>
1 parent a84e1ad commit f81ab4a

File tree

2 files changed

+42
-23
lines changed

2 files changed

+42
-23
lines changed

wsd/COOLWSD.cpp

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3556,7 +3556,7 @@ std::string COOLWSD::getServerURL()
35563556
#endif
35573557
#endif
35583558

3559-
int COOLWSD::innerMain()
3559+
void COOLWSD::innerMain()
35603560
{
35613561
#if !MOBILEAPP
35623562
# ifdef __linux__
@@ -3597,7 +3597,7 @@ int COOLWSD::innerMain()
35973597
LOG_INF("Locale is set to " + std::string(locale));
35983598
::setenv("LC_ALL", locale, 1);
35993599
}
3600-
#endif
3600+
#endif // !IOS
36013601

36023602
#if !MOBILEAPP
36033603
// We use the same option set for both parent and child coolwsd,
@@ -4049,30 +4049,44 @@ int COOLWSD::innerMain()
40494049
JailUtil::cleanupJails(CleanupChildRoot);
40504050
#endif // !MOBILEAPP
40514051

4052-
const int returnValue = UnitBase::uninit();
4053-
4054-
LOG_INF("Process [coolwsd] finished with exit status: " << returnValue);
4055-
4056-
SigUtil::addActivity("finished with status " + std::to_string(returnValue));
4057-
40584052
if constexpr (Util::isMobileApp())
4059-
Util::forcedExit(returnValue);
4053+
{
4054+
LOG_INF("Process [coolwsd] finished with exit status: " << EXIT_OK);
4055+
Util::forcedExit(EXIT_OK);
4056+
}
40604057

4061-
return returnValue;
4062-
#else // IOS
4063-
return 0;
4064-
#endif
4058+
#endif // !IOS
40654059
}
40664060

40674061
std::shared_ptr<TerminatingPoll> COOLWSD:: getWebServerPoll ()
40684062
{
40694063
return COOLWSDServer::WebServerPoll;
40704064
}
40714065

4072-
void COOLWSD::cleanup([[maybe_unused]] int returnValue)
4066+
int COOLWSD::cleanup(int returnValue)
40734067
{
40744068
try
40754069
{
4070+
#ifndef IOS
4071+
if (UnitBase::isUnitTesting())
4072+
{
4073+
LOG_DBG("Coolwsd finished with exit status " << returnValue
4074+
<< "; uninitializing UnitBase");
4075+
const int unitReturnValue = UnitBase::uninit();
4076+
if (unitReturnValue != EXIT_OK)
4077+
{
4078+
// Overwrite the return value if the unit-test failed.
4079+
LOG_INF("Overwriting process [coolwsd] exit status ["
4080+
<< returnValue << "] with unit-test status: " << unitReturnValue);
4081+
returnValue = unitReturnValue;
4082+
}
4083+
}
4084+
4085+
LOG_INF("Process [coolwsd] finished with exit status: " << returnValue);
4086+
4087+
SigUtil::addActivity("finished with status " + std::to_string(returnValue));
4088+
#endif // !IOS
4089+
40764090
COOLWSDServer::Instance.reset();
40774091

40784092
PrisonerPoll.reset();
@@ -4120,7 +4134,10 @@ void COOLWSD::cleanup([[maybe_unused]] int returnValue)
41204134
catch (const std::exception& ex)
41214135
{
41224136
LOG_ERR("Failed to uninitialize: " << ex.what());
4137+
throw;
41234138
}
4139+
4140+
return returnValue;
41244141
}
41254142

41264143
int COOLWSD::main(const std::vector<std::string>& /*args*/)
@@ -4129,21 +4146,23 @@ int COOLWSD::main(const std::vector<std::string>& /*args*/)
41294146

41304147
int returnValue = EXIT_SOFTWARE;
41314148

4132-
try {
4133-
returnValue = innerMain();
4149+
try
4150+
{
4151+
innerMain();
41344152
}
41354153
catch (const std::exception& e)
41364154
{
41374155
LOG_FTL("Exception: " << e.what());
4138-
cleanup(returnValue);
4156+
cleanup(EXIT_SOFTWARE);
41394157
throw;
4140-
} catch (...) {
4141-
cleanup(returnValue);
4158+
}
4159+
catch (...)
4160+
{
4161+
cleanup(EXIT_SOFTWARE);
41424162
throw;
41434163
}
41444164

4145-
cleanup(returnValue);
4146-
4165+
returnValue = cleanup(EXIT_OK);
41474166
LOG_INF("Process [coolwsd] finished with exit status: " << returnValue);
41484167

41494168
#if CODE_COVERAGE

wsd/COOLWSD.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ class COOLWSD final : public Poco::Util::ServerApplication,
281281
int main(const std::vector<std::string>& args) override;
282282

283283
/// Handle various global static destructors.
284-
static void cleanup(int returnValue);
284+
static int cleanup(int returnValue);
285285

286286
private:
287287
#if !MOBILEAPP
@@ -297,7 +297,7 @@ class COOLWSD final : public Poco::Util::ServerApplication,
297297
void innerInitialize(Application& self);
298298

299299
/// The actual main implementation.
300-
int innerMain();
300+
void innerMain();
301301

302302
static void appendAllowedHostsFrom(Poco::Util::LayeredConfiguration& conf, const std::string& root, std::vector<std::string>& allowed);
303303
static void appendAllowedAliasGroups(Poco::Util::LayeredConfiguration& conf, std::vector<std::string>& allowed);

0 commit comments

Comments
 (0)