Add option to Preferences to flush file loggers when a signal is triggered

This commit is contained in:
Magne Sjaastad
2024-01-31 14:41:57 +01:00
parent 710b91d161
commit 06766b3650
6 changed files with 75 additions and 0 deletions

View File

@@ -18,6 +18,7 @@
#include "RiaArgumentParser.h"
#include "RiaMainTools.h"
#include "RiaPreferences.h"
#ifdef ENABLE_GRPC
#include "RiaGrpcConsoleApplication.h"
@@ -39,6 +40,10 @@
#include <unistd.h>
#endif
#include <signal.h>
void manageSegFailure( int signalCode );
RiaApplication* createApplication( int& argc, char* argv[] )
{
for ( int i = 1; i < argc; ++i )
@@ -109,6 +114,17 @@ int main( int argc, char* argv[] )
QLocale::setDefault( QLocale( QLocale::English, QLocale::UnitedStates ) );
setlocale( LC_NUMERIC, "C" );
// Set up signal handlers
if ( RiaPreferences::current()->loggerTrapSignalAndFlush() )
{
signal( SIGINT, manageSegFailure );
signal( SIGILL, manageSegFailure );
signal( SIGFPE, manageSegFailure );
signal( SIGSEGV, manageSegFailure );
signal( SIGTERM, manageSegFailure );
signal( SIGABRT, manageSegFailure );
}
// Handle the command line arguments.
// Todo: Move to a one-shot timer, delaying the execution until we are inside the event loop.
// The complete handling of the resulting ApplicationStatus must be moved along.