diff -r 9fb1bd7c01a2 -r 3286acbfe5cd src/core/model/simulator.cc --- a/src/core/model/simulator.cc Mon Jul 11 14:17:46 2011 +0200 +++ b/src/core/model/simulator.cc Tue Jul 12 13:10:13 2011 +0200 @@ -30,6 +30,7 @@ #include "ns3/global-value.h" #include "ns3/assert.h" #include "ns3/log.h" +#include "ns3/fatal-impl.h" #include #include @@ -51,6 +52,8 @@ TypeIdValue (MapScheduler::GetTypeId ()), MakeTypeIdChecker ()); +struct sigaction Simulator::m_act; + static void TimePrinter (std::ostream &os) { @@ -160,6 +163,7 @@ Simulator::Run (void) { NS_LOG_FUNCTION_NOARGS (); + OverrideInterruptHandler (); GetImpl ()->Run (); } @@ -167,6 +171,7 @@ Simulator::RunOneEvent (void) { NS_LOG_FUNCTION_NOARGS (); + OverrideInterruptHandler (); GetImpl ()->RunOneEvent (); } @@ -366,7 +371,26 @@ return GetImpl (); } +void +Simulator::OverrideInterruptHandler (void) +{ + // override default SIGABRT handler + struct sigaction act; + act.sa_flags = 0; + sigemptyset (&act.sa_mask); + act.sa_handler = InterruptHandler; + sigaction (SIGINT, &act, &m_act); +} +void +Simulator::InterruptHandler (int sig_num) +{ + FatalImpl::FlushStreams (); + // restore previous handler + sigaction (SIGINT, &m_act, 0); + // resend signal + raise (SIGINT); +} } // namespace ns3 diff -r 9fb1bd7c01a2 -r 3286acbfe5cd src/core/model/simulator.h --- a/src/core/model/simulator.h Mon Jul 11 14:17:46 2011 +0200 +++ b/src/core/model/simulator.h Tue Jul 12 13:10:13 2011 +0200 @@ -31,6 +31,7 @@ #include #include +#include namespace ns3 { @@ -783,6 +784,11 @@ static EventId DoSchedule (Time const &time, EventImpl *event); static EventId DoScheduleNow (EventImpl *event); static EventId DoScheduleDestroy (EventImpl *event); + + static void InterruptHandler (int); + static void OverrideInterruptHandler (void); + + static struct sigaction m_act; }; /**