Cleanly terminate vvp on SIGHUP or SIGTERM (GitHub issue #203).

(cherry picked from commit 603ff303f5)
This commit is contained in:
Martin Whitaker 2018-09-29 23:25:04 +01:00
parent f2a711b8f1
commit c5df4cfcad
1 changed files with 15 additions and 6 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001-2016 Stephen Williams (steve@icarus.com)
* Copyright (c) 2001-2018 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -527,27 +527,36 @@ bool schedule_stopped(void)
/*
* These are the signal handling infrastructure. The SIGINT signal
* leads to an implicit $stop.
* leads to an implicit $stop. The SIGHUP and SIGTERM signals lead
* to an implicit $finish.
*/
extern "C" void signals_handler(int)
extern bool stop_is_finish;
extern "C" void signals_handler(int signum)
{
#ifdef __MINGW32__
// Windows implements the original UNIX semantics for signal,
// so we have to re-establish the signal handler each time a
// signal is caught.
signal(SIGINT, &signals_handler);
signal(signum, &signals_handler);
#endif
if (signum != SIGINT)
stop_is_finish = true;
schedule_stopped_flag = true;
}
static void signals_capture(void)
{
signal(SIGHUP, &signals_handler);
signal(SIGINT, &signals_handler);
signal(SIGTERM, &signals_handler);
}
static void signals_revert(void)
{
signal(SIGHUP, SIG_DFL);
signal(SIGINT, SIG_DFL);
signal(SIGTERM, SIG_DFL);
}
/*