Skip to content

Commit

Permalink
WIP: Signal handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
magnesj committed Jan 15, 2024
1 parent 5c09674 commit 448a0f2
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ApplicationExeCode/RiaMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
#include <unistd.h>
#endif

#include <signal.h>

void manageSegFailure( int signalCode );


RiaApplication* createApplication( int& argc, char* argv[] )
{
for ( int i = 1; i < argc; ++i )
Expand Down Expand Up @@ -109,6 +114,10 @@ int main( int argc, char* argv[] )
QLocale::setDefault( QLocale( QLocale::English, QLocale::UnitedStates ) );
setlocale( LC_NUMERIC, "C" );

{
signal( SIGSEGV, 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.
Expand Down
24 changes: 24 additions & 0 deletions ApplicationExeCode/RiaMainTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
/////////////////////////////////////////////////////////////////////////////////

#include "RiaMainTools.h"
#include "RiaFileLogger.h"
#include "RiaLogging.h"
#include "RiaRegressionTestRunner.h"
#include "RiaSocketCommand.h"

Expand All @@ -25,6 +27,28 @@
#include "cafPdmDefaultObjectFactory.h"
#include "cafPdmUiFieldEditorHandle.h"

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void manageSegFailure( int signalCode )
{
auto loggers = RiaLogging::loggerInstances();

QString str = QString( "Segmentation fault. Signal code: %1" ).arg( signalCode );

for ( auto logger : loggers )
{
if ( auto fileLogger = dynamic_cast<RiaFileLogger*>( logger ) )
{
fileLogger->error( str.toStdString().data() );

fileLogger->flush();
}
}

exit( 1 );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
16 changes: 16 additions & 0 deletions ApplicationLibCode/Application/Tools/RiaFileLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ class RiaFileLogger::Impl
if ( m_spdlogger ) m_spdlogger->warn( message );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void flush()
{
if ( m_spdlogger ) m_spdlogger->flush();
}

private:
std::shared_ptr<spdlog::logger> m_spdlogger;
};
Expand Down Expand Up @@ -150,3 +158,11 @@ void RiaFileLogger::debug( const char* message )
{
m_impl->debug( message );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaFileLogger::flush()
{
if ( m_impl ) m_impl->flush();
}
2 changes: 2 additions & 0 deletions ApplicationLibCode/Application/Tools/RiaFileLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class RiaFileLogger : public RiaLogger
void info( const char* message ) override;
void debug( const char* message ) override;

void flush();

private:
int m_logLevel;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ CAF_CMD_SOURCE_INIT( RicTileWindowsFeature, "RicTileWindowsFeature" );
//--------------------------------------------------------------------------------------------------
void RicTileWindowsFeature::applyTiling( RiuMainWindow* mainWindow, RiaDefines::WindowTileMode requestedTileMode )
{
*(int*)0 = 0;

auto mode = requestedTileMode;

if ( auto proj = RimProject::current() )
Expand Down

0 comments on commit 448a0f2

Please sign in to comment.