@@ -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,42 @@ 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
40934081std::shared_ptr<TerminatingPoll> COOLWSD:: getWebServerPoll ()
40944082{
40954083 return WebServerPoll;
40964084}
40974085
4098- void COOLWSD::cleanup ([[maybe_unused]] int returnValue)
4086+ int COOLWSD::cleanup (int returnValue)
40994087{
4088+ if constexpr (Util::isMobileApp ())
4089+ {
4090+ LOG_INF (" Process [coolwsd] finished with exit status: " << returnValue);
4091+ Util::forcedExit (returnValue);
4092+ }
4093+
41004094 try
41014095 {
4096+ if (UnitBase::isUnitTesting ())
4097+ {
4098+ LOG_DBG (" Coolwsd finished with exit status " << returnValue
4099+ << " ; uninitializing UnitBase" );
4100+ const int unitReturnValue = UnitBase::uninit ();
4101+ if (unitReturnValue != EXIT_OK)
4102+ {
4103+ // Overwrite the return value if the unit-test failed.
4104+ LOG_INF (" Overwriting process [coolwsd] exit status ["
4105+ << returnValue << " ] with unit-test status: " << unitReturnValue);
4106+ returnValue = unitReturnValue;
4107+ }
4108+ }
4109+
4110+ LOG_INF (" Process [coolwsd] finished with exit status: " << returnValue);
4111+
4112+ SigUtil::addActivity (" finished with status " + std::to_string (returnValue));
4113+
41024114 Server.reset ();
41034115
41044116 PrisonerPoll.reset ();
@@ -4146,7 +4158,10 @@ void COOLWSD::cleanup([[maybe_unused]] int returnValue)
41464158 catch (const std::exception& ex)
41474159 {
41484160 LOG_ERR (" Failed to uninitialize: " << ex.what ());
4161+ throw ;
41494162 }
4163+
4164+ return returnValue;
41504165}
41514166
41524167int COOLWSD::main (const std::vector<std::string>& /* args*/ )
@@ -4155,21 +4170,23 @@ int COOLWSD::main(const std::vector<std::string>& /*args*/)
41554170
41564171 int returnValue = EXIT_SOFTWARE;
41574172
4158- try {
4159- returnValue = innerMain ();
4173+ try
4174+ {
4175+ innerMain ();
41604176 }
41614177 catch (const std::exception& e)
41624178 {
41634179 LOG_FTL (" Exception: " << e.what ());
4164- cleanup (returnValue );
4180+ cleanup (EXIT_SOFTWARE );
41654181 throw ;
4166- } catch (...) {
4167- cleanup (returnValue);
4182+ }
4183+ catch (...)
4184+ {
4185+ cleanup (EXIT_SOFTWARE);
41684186 throw ;
41694187 }
41704188
4171- cleanup (returnValue);
4172-
4189+ returnValue = cleanup (EXIT_OK);
41734190 LOG_INF (" Process [coolwsd] finished with exit status: " << returnValue);
41744191
41754192#if CODE_COVERAGE
0 commit comments