1
0
Fork 0

Better setting of the process exit status for fgfs and fgviewer

Some pieces of code such as fgMainInit() and, by cascading effect,
fgInitHome(), were careful to return a meaningful value indicating
success or error, however the main() function in src/Main/bootstrap.cxx
ignored it royally so far.

main() now returns:
  - EXIT_FAILURE if fgMainInit() or fgviewerMain() throws an exception;
  - whatever said function returns otherwise.
This commit is contained in:
Florent Rougon 2017-04-10 02:16:08 +02:00
parent 4b494a69bd
commit cf318f1cc5

View file

@ -307,6 +307,7 @@ int main ( int argc, char **argv )
setlocale(LC_COLLATE, "C"); setlocale(LC_COLLATE, "C");
bool fgviewer = flightgear::Options::checkForArg(argc, argv, "fgviewer"); bool fgviewer = flightgear::Options::checkForArg(argc, argv, "fgviewer");
int exitStatus = EXIT_FAILURE;
try { try {
// http://code.google.com/p/flightgear-bugs/issues/detail?id=1231 // http://code.google.com/p/flightgear-bugs/issues/detail?id=1231
// ensure sglog is inited before atexit() is registered, so logging // ensure sglog is inited before atexit() is registered, so logging
@ -323,10 +324,11 @@ int main ( int argc, char **argv )
#endif #endif
std::set_terminate(fg_terminate); std::set_terminate(fg_terminate);
atexit(fgExitCleanup); atexit(fgExitCleanup);
if (fgviewer) if (fgviewer) {
fgviewerMain(argc, argv); exitStatus = fgviewerMain(argc, argv);
else } else {
fgMainInit(argc, argv); exitStatus = fgMainInit(argc, argv);
}
} catch (const sg_throwable &t) { } catch (const sg_throwable &t) {
std::string info; std::string info;
@ -334,7 +336,6 @@ int main ( int argc, char **argv )
info = std::string("received from ") + t.getOrigin(); info = std::string("received from ") + t.getOrigin();
flightgear::fatalMessageBoxWithoutExit( flightgear::fatalMessageBoxWithoutExit(
"Fatal exception", t.getFormattedMessage(), info); "Fatal exception", t.getFormattedMessage(), info);
} catch (const std::exception &e ) { } catch (const std::exception &e ) {
flightgear::fatalMessageBoxWithoutExit("Fatal exception", e.what()); flightgear::fatalMessageBoxWithoutExit("Fatal exception", e.what());
} catch (const std::string &s) { } catch (const std::string &s) {
@ -352,7 +353,7 @@ int main ( int argc, char **argv )
crUninstall(); crUninstall();
#endif #endif
return 0; return exitStatus;
} }
// do some clean up on exit. Specifically we want to delete the sound-manager, // do some clean up on exit. Specifically we want to delete the sound-manager,