Skip to content

Commit 0fbfc87

Browse files
committed
#3107 Send SIGALRM to children when the alarm is triggered
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@24243 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 7e55368 commit 0fbfc87

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

Compiler/FrontEnd/ModelicaBuiltin.mo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,6 +1560,7 @@ impure function alarm
15601560
output Integer previousSeconds;
15611561
external "builtin" annotation(__OpenModelica_Impure=true,Library = {"omcruntime"},Documentation(info="<html>
15621562
<p>Like <a href=\"http://linux.die.net/man/2/alarm\">alarm(2)</a>.</p>
1563+
<p>Note that OpenModelica also sends SIGALRM to the process group when the alarm is triggered (in order to kill running simulations).</p>
15631564
</html>"));
15641565
end alarm;
15651566

Compiler/runtime/systemimpl.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2683,11 +2683,38 @@ int SystemImpl__stat(const char *filename, double *size, double *mtime)
26832683
return 1;
26842684
}
26852685

2686+
#if defined(__MINGW32__) || defined(_MSC_VER)
2687+
static int default_alarm_action_set = 0;
2688+
static struct sigaction default_alarm_action;
2689+
2690+
static void alarm_handler(int signo, siginfo_t *si, void *ptr)
2691+
{
2692+
assert(signo==SIGALRM);
2693+
kill(-getpid(), SIGALRM);
2694+
sigaction(SIGALRM, &default_alarm_action, 0);
2695+
}
2696+
2697+
int SystemImpl__alarm(int seconds)
2698+
{
2699+
if (default_alarm_action_set == 0) {
2700+
struct sigaction sa = {
2701+
.sa_sigaction = alarm_handler,
2702+
.sa_flags = SA_SIGINFO
2703+
};
2704+
sigaction(SIGALRM, &sa, NULL);
2705+
default_alarm_action_set = 1;
2706+
}
2707+
return alarm(seconds);
2708+
}
2709+
#else
2710+
26862711
int SystemImpl__alarm(int seconds)
26872712
{
26882713
return alarm(seconds);
26892714
}
26902715

2716+
#endif
2717+
26912718
int SystemImpl__covertTextFileToCLiteral(const char *textFile, const char *outFile)
26922719
{
26932720
FILE *fin;

0 commit comments

Comments
 (0)