Skip to content

Commit 57cfe33

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

File tree

2 files changed

+39
-25
lines changed

2 files changed

+39
-25
lines changed

wsd/COOLWSD.cpp

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3582,7 +3582,7 @@ std::string COOLWSD::getServerURL()
35823582
#endif
35833583
#endif
35843584

3585-
int COOLWSD::innerMain()
3585+
void COOLWSD::innerMain()
35863586
{
35873587
#if !MOBILEAPP
35883588
# ifdef __linux__
@@ -3623,7 +3623,7 @@ int COOLWSD::innerMain()
36233623
LOG_INF("Locale is set to " + std::string(locale));
36243624
::setenv("LC_ALL", locale, 1);
36253625
}
3626-
#endif
3626+
#endif // !IOS
36273627

36283628
#if !MOBILEAPP
36293629
// We use the same option set for both parent and child coolwsd,
@@ -4075,30 +4075,39 @@ int COOLWSD::innerMain()
40754075
JailUtil::cleanupJails(CleanupChildRoot);
40764076
#endif // !MOBILEAPP
40774077

4078-
const int returnValue = UnitBase::uninit();
4079-
4080-
LOG_INF("Process [coolwsd] finished with exit status: " << returnValue);
4081-
4082-
SigUtil::addActivity("finished with status " + std::to_string(returnValue));
4083-
4084-
if constexpr (Util::isMobileApp())
4085-
Util::forcedExit(returnValue);
4086-
4087-
return returnValue;
4088-
#else // IOS
4089-
return 0;
4090-
#endif
4078+
#endif // !IOS
40914079
}
40924080

40934081
std::shared_ptr<TerminatingPoll> COOLWSD:: getWebServerPoll ()
40944082
{
40954083
return WebServerPoll;
40964084
}
40974085

4098-
void COOLWSD::cleanup([[maybe_unused]] int returnValue)
4086+
int COOLWSD::cleanup([[maybe_unused]] int returnValue)
40994087
{
41004088
try
41014089
{
4090+
if (UnitBase::isUnitTesting())
4091+
{
4092+
LOG_DBG("Coolwsd finished with exit status " << returnValue
4093+
<< "; uninitializing UnitBase");
4094+
const int unitReturnValue = UnitBase::uninit();
4095+
if (unitReturnValue != EXIT_OK)
4096+
{
4097+
// Overwrite the return value if the unit-test failed.
4098+
LOG_INF("Overwriting process [coolwsd] exit status ["
4099+
<< returnValue << "] with unit-test status: " << unitReturnValue);
4100+
returnValue = unitReturnValue;
4101+
}
4102+
}
4103+
4104+
LOG_INF("Process [coolwsd] finished with exit status: " << returnValue);
4105+
4106+
SigUtil::addActivity("finished with status " + std::to_string(returnValue));
4107+
4108+
if constexpr (Util::isMobileApp())
4109+
Util::forcedExit(returnValue);
4110+
41024111
Server.reset();
41034112

41044113
PrisonerPoll.reset();
@@ -4146,7 +4155,10 @@ void COOLWSD::cleanup([[maybe_unused]] int returnValue)
41464155
catch (const std::exception& ex)
41474156
{
41484157
LOG_ERR("Failed to uninitialize: " << ex.what());
4158+
throw;
41494159
}
4160+
4161+
return returnValue;
41504162
}
41514163

41524164
int COOLWSD::main(const std::vector<std::string>& /*args*/)
@@ -4155,21 +4167,23 @@ int COOLWSD::main(const std::vector<std::string>& /*args*/)
41554167

41564168
int returnValue = EXIT_SOFTWARE;
41574169

4158-
try {
4159-
returnValue = innerMain();
4170+
try
4171+
{
4172+
innerMain();
4173+
returnValue = cleanup(EXIT_OK);
41604174
}
41614175
catch (const std::exception& e)
41624176
{
41634177
LOG_FTL("Exception: " << e.what());
4164-
cleanup(returnValue);
4178+
cleanup(EXIT_SOFTWARE);
41654179
throw;
4166-
} catch (...) {
4167-
cleanup(returnValue);
4180+
}
4181+
catch (...)
4182+
{
4183+
cleanup(EXIT_SOFTWARE);
41684184
throw;
41694185
}
41704186

4171-
cleanup(returnValue);
4172-
41734187
LOG_INF("Process [coolwsd] finished with exit status: " << returnValue);
41744188

41754189
#if CODE_COVERAGE

wsd/COOLWSD.hpp

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

279279
/// Handle various global static destructors.
280-
static void cleanup(int returnValue);
280+
static int cleanup(int returnValue);
281281

282282
private:
283283
#if !MOBILEAPP
@@ -293,7 +293,7 @@ class COOLWSD final : public Poco::Util::ServerApplication,
293293
void innerInitialize(Application& self);
294294

295295
/// The actual main implementation.
296-
int innerMain();
296+
void innerMain();
297297

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

0 commit comments

Comments
 (0)