From: Pavel Pisa Date: Mon, 20 Mar 2017 01:38:41 +0000 (+0100) Subject: Include SIGINT handler to properly stop model when aborted by CTRL+C. X-Git-Url: http://rtime.felk.cvut.cz/gitweb/ert_linux.git/commitdiff_plain/3a987356f782b441aa0e05696aebdf3d910478b8 Include SIGINT handler to properly stop model when aborted by CTRL+C. Enhancement based on change done by Constantin Wiesener in daqbeagle project. Signed-off-by: Pavel Pisa --- diff --git a/ert_linux/ert_linux_main.tlc b/ert_linux/ert_linux_main.tlc index 418d20c..30943c2 100644 --- a/ert_linux/ert_linux_main.tlc +++ b/ert_linux/ert_linux_main.tlc @@ -32,6 +32,7 @@ #include #include #include /* For mlockall() */ + #include #include "%.h" /* Model's header file */ #include "rtwtypes.h" /* MathWorks types */ %if extMode == 1 @@ -224,6 +225,14 @@ return NULL; } + /** + * Signal handler for ABORT during simulation + */ + void abort_signal_handler(int sig) { + fprintf(stderr, "Simulation aborted by pressing CTRL+C\n"); + rtmSetStopRequested(%_M, 1); + } + /** * This is the main function of the model. * Multirate - Multitasking case main file @@ -282,6 +291,9 @@ %if extMode == 1 /* External mode */ CHECKE(sem_wait(&ext_mode_ready)); + + signal(SIGINT, abort_signal_handler); /* important for letting the destructor be called. */ + while(rtmGetErrorStatus(%_M) == NULL && !rtmGetStopRequested(%_M)) { rtExtModeOneStep(rtmGetRTWExtModeInfo(RT_MDL), NUMST, (boolean_T *)&rtmGetStopRequested(RT_MDL)); usleep(%);