bug fixes
[melted] / src / miracle / miracle_local.c
index e9ef50e..71b7b77 100644 (file)
@@ -26,6 +26,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <signal.h>
+#include <execinfo.h>
 
 /* Valerie header files */
 #include <valerie/valerie_util.h>
@@ -286,6 +287,31 @@ void signal_handler( int sig )
        }
 }
 
+static void sigsegv_handler()
+{
+       void *array[ 10 ];
+       size_t size;
+       char **strings;
+       size_t i;
+
+       miracle_log( LOG_CRIT, "\a\nMiracle experienced a segmentation fault.\n"
+               "Dumping stack from the offending thread\n\n" );
+       size = backtrace( array, 10 );
+       strings = backtrace_symbols( array, size );
+
+       miracle_log( LOG_CRIT, "Obtained %zd stack frames.\n", size );
+
+       for ( i = 0; i < size; i++ )
+                miracle_log( LOG_CRIT, "%s", strings[ i ] );
+
+       free( strings );
+
+       miracle_log( LOG_CRIT, "\nDone dumping - exiting.\n" );
+       exit( EXIT_FAILURE );
+}
+
+
+
 /** Local 'connect' function.
 */
 
@@ -304,6 +330,8 @@ static valerie_response miracle_local_connect( miracle_local local )
        signal( SIGPIPE, signal_handler );
        signal( SIGALRM, signal_handler );
        signal( SIGCHLD, SIG_IGN );
+       if ( getenv( "MLT_SIGSEGV" ) )
+               signal( SIGSEGV, sigsegv_handler );
 
        return response;
 }
@@ -455,5 +483,5 @@ static void miracle_local_close( miracle_local local )
        pthread_kill_other_threads_np();
        miracle_log( LOG_DEBUG, "Clean shutdown." );
        free( local );
-       mlt_factory_close( );
+       //mlt_factory_close( );
 }