@@ -3579,7 +3579,7 @@ std::string COOLWSD::getServerURL()
35793579#endif
35803580#endif
35813581
3582- int COOLWSD::innerMain ()
3582+ void COOLWSD::innerMain ()
35833583{
35843584#if !MOBILEAPP
35853585# ifdef __linux__
@@ -3620,7 +3620,7 @@ int COOLWSD::innerMain()
36203620 LOG_INF (" Locale is set to " + std::string (locale));
36213621 ::setenv (" LC_ALL" , locale, 1 );
36223622 }
3623- #endif
3623+ #endif // !IOS
36243624
36253625#if !MOBILEAPP
36263626 // We use the same option set for both parent and child coolwsd,
@@ -4072,30 +4072,44 @@ int COOLWSD::innerMain()
40724072 JailUtil::cleanupJails (CleanupChildRoot);
40734073#endif // !MOBILEAPP
40744074
4075- const int returnValue = UnitBase::uninit ();
4076-
4077- LOG_INF (" Process [coolwsd] finished with exit status: " << returnValue);
4078-
4079- SigUtil::addActivity (" finished with status " + std::to_string (returnValue));
4080-
40814075 if constexpr (Util::isMobileApp ())
4082- Util::forcedExit (returnValue);
4076+ {
4077+ LOG_INF (" Process [coolwsd] finished with exit status: " << EXIT_OK);
4078+ Util::forcedExit (EXIT_OK);
4079+ }
40834080
4084- return returnValue;
4085- #else // IOS
4086- return 0 ;
4087- #endif
4081+ #endif // !IOS
40884082}
40894083
40904084std::shared_ptr<TerminatingPoll> COOLWSD:: getWebServerPoll ()
40914085{
40924086 return WebServerPoll;
40934087}
40944088
4095- void COOLWSD::cleanup ([[maybe_unused]] int returnValue)
4089+ int COOLWSD::cleanup (int returnValue)
40964090{
40974091 try
40984092 {
4093+ #ifndef IOS
4094+ if (UnitBase::isUnitTesting ())
4095+ {
4096+ LOG_DBG (" Coolwsd finished with exit status " << returnValue
4097+ << " ; uninitializing UnitBase" );
4098+ const int unitReturnValue = UnitBase::uninit ();
4099+ if (unitReturnValue != EXIT_OK)
4100+ {
4101+ // Overwrite the return value if the unit-test failed.
4102+ LOG_INF (" Overwriting process [coolwsd] exit status ["
4103+ << returnValue << " ] with unit-test status: " << unitReturnValue);
4104+ returnValue = unitReturnValue;
4105+ }
4106+ }
4107+
4108+ LOG_INF (" Process [coolwsd] finished with exit status: " << returnValue);
4109+
4110+ SigUtil::addActivity (" finished with status " + std::to_string (returnValue));
4111+ #endif // !IOS
4112+
40994113 Server.reset ();
41004114
41014115 PrisonerPoll.reset ();
@@ -4143,7 +4157,10 @@ void COOLWSD::cleanup([[maybe_unused]] int returnValue)
41434157 catch (const std::exception& ex)
41444158 {
41454159 LOG_ERR (" Failed to uninitialize: " << ex.what ());
4160+ throw ;
41464161 }
4162+
4163+ return returnValue;
41474164}
41484165
41494166int COOLWSD::main (const std::vector<std::string>& /* args*/ )
@@ -4152,21 +4169,23 @@ int COOLWSD::main(const std::vector<std::string>& /*args*/)
41524169
41534170 int returnValue = EXIT_SOFTWARE;
41544171
4155- try {
4156- returnValue = innerMain ();
4172+ try
4173+ {
4174+ innerMain ();
41574175 }
41584176 catch (const std::exception& e)
41594177 {
41604178 LOG_FTL (" Exception: " << e.what ());
4161- cleanup (returnValue );
4179+ cleanup (EXIT_SOFTWARE );
41624180 throw ;
4163- } catch (...) {
4164- cleanup (returnValue);
4181+ }
4182+ catch (...)
4183+ {
4184+ cleanup (EXIT_SOFTWARE);
41654185 throw ;
41664186 }
41674187
4168- cleanup (returnValue);
4169-
4188+ returnValue = cleanup (EXIT_OK);
41704189 LOG_INF (" Process [coolwsd] finished with exit status: " << returnValue);
41714190
41724191#if CODE_COVERAGE
0 commit comments