extern "C" void HandleServerSideSignals(CORBA::ORB_ptr theORB);
+#include <stdexcept>
+#include <signal.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+typedef void (*sighandler_t)(int);
+sighandler_t setsig(int sig, sighandler_t handler)
+{
+ struct sigaction context, ocontext;
+ context.sa_handler = handler;
+ sigemptyset(&context.sa_mask);
+ context.sa_flags = 0;
+ if (sigaction(sig, &context, &ocontext) == -1)
+ return SIG_ERR;
+ return ocontext.sa_handler;
+}
+
+void AttachDebugger()
+{
+ if(getenv ("DEBUGGER"))
+ {
+ std::stringstream exec;
+ exec << "$DEBUGGER SALOME_Container " << getpid() << "&";
+ std::cerr << exec.str() << std::endl;
+ system(exec.str().c_str());
+ while(1);
+ }
+}
+
+void Handler(int theSigId)
+{
+ std::cerr << "SIGSEGV: " << std::endl;
+ AttachDebugger();
+ //to exit or not to exit
+ exit(1);
+}
+
+void terminateHandler(void)
+{
+ std::cerr << "Terminate: not managed exception !" << std::endl;
+ AttachDebugger();
+}
+
+void unexpectedHandler(void)
+{
+ std::cerr << "Unexpected: unexpected exception !" << std::endl;
+ AttachDebugger();
+}
+
int main(int argc, char* argv[])
{
#ifdef HAVE_MPI2
MPI_Init(&argc,&argv);
#endif
+ if(getenv ("DEBUGGER"))
+ {
+ setsig(SIGSEGV,&Handler);
+ set_terminate(&terminateHandler);
+ set_unexpected(&unexpectedHandler);
+ }
+
// Initialise the ORB.
//SRN: BugID: IPAL9541, it's necessary to set a size of one message to be at least 100Mb
//CORBA::ORB_var orb = CORBA::ORB_init( argc , argv ) ;