iss #909 add functions to turn on/off SIGCHLD handler (#924)

closes #909
This commit is contained in:
Scott Fennell 2020-01-16 10:49:36 -06:00 committed by GitHub
parent 909d8991f1
commit 3415996952
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 79 additions and 7 deletions

View File

@ -72,6 +72,9 @@ namespace Trick {
/** Allows the trapping of SIGABRT signals and graceful shutdown.\n */
bool trap_sigabrt; /**< trick_units(--) */
/** Allows the trapping of SIGCHLD signals\n */
bool trap_sigchld; /**< trick_units(--) */
/** Flags a restart was loaded\n */
bool restart_called; /**< trick_io(**) trick_units(--) */
@ -540,6 +543,14 @@ namespace Trick {
*/
bool get_trap_sigabrt() ;
/**
@userdesc Command to get the trap sigchld toggle value (will SIGCHLD signal be trapped).
@par Python Usage:
@code <my_int> = trick.exec_get_trap_sigsegv() @endcode
@return boolean (C integer 0/1) Executive::trap_sigsegv
*/
bool get_trap_sigchld() ;
/**
@brief @userdesc Command to set the attach debugger toggle value.
@param on_off - boolean yes (C integer 1) = attach debugger if signal shuts sim down. no (C integer 0) = do not attach debugger.
@ -714,6 +725,15 @@ namespace Trick {
*/
int set_trap_sigabrt(bool on_off) ;
/**
@userdesc Command to enable/disable the trapping of SIGCHILD signals.
@par Python Usage:
@code trick.exec_set_trap_child(<on_off>) @endcode
@param on_off - boolean yes (C integer 1) = enable trap, no (C integer 0) = disable trap
@return always 0
*/
int set_trap_sigchld(bool on_off) ;
/**
@userdesc Command to get the simulation time in seconds.
Formula for simulation time is time_tics / time_tic_value.

View File

@ -39,6 +39,7 @@ extern "C" {
int exec_get_trap_sigfpe(void) ;
int exec_get_trap_sigsegv(void) ;
int exec_get_trap_sigabrt(void) ;
int exec_get_trap_sigchld(void) ;
int exec_set_attach_debugger(int on_off) ;
int exec_set_debugger_command(const char * command) ;
@ -69,6 +70,7 @@ extern "C" {
int exec_set_trap_sigfpe(int on_off) ;
int exec_set_trap_sigsegv(int on_off) ;
int exec_set_trap_sigabrt(int on_off) ;
int exec_set_trap_sigchld(int on_off) ;
int exec_set_version_date_tag(const char * tag) ;
int exec_set_build_date(const char * date) ;
int exec_set_current_version(const char * version) ;

View File

@ -76,6 +76,7 @@ Trick::Executive::Executive() {
trap_sigfpe = false ;
trap_sigsegv = false ;
trap_sigabrt = false ;
trap_sigchld = false ;
build_date = std::string("unknown") ;
current_version = std::string("unknown") ;
@ -284,6 +285,10 @@ bool Trick::Executive::get_trap_sigabrt() {
return(trap_sigabrt) ;
}
bool Trick::Executive::get_trap_sigchld() {
return(trap_sigchld) ;
}
void Trick::Executive::reset_job_cycle_times() {
unsigned int ii ;
for ( ii = 0 ; ii < all_jobs_vector.size() ; ii++ ) {

View File

@ -390,6 +390,18 @@ extern "C" int exec_get_trap_sigabrt() {
return -1 ;
}
/**
* @relates Trick::Executive
* @copydoc Trick::Executive::get_trap_sigchld
* C wrapper for Trick::Executive::get_trap_sigchld
*/
extern "C" int exec_get_trap_sigchld() {
if ( the_exec != NULL ) {
return (int)the_exec->get_trap_sigchld() ;
}
return -1 ;
}
// -------------------------- SET ------------------------
/**
@ -617,6 +629,18 @@ extern "C" int exec_set_trap_sigabrt( int on_off ) {
return -1 ;
}
/**
* @relates Trick::Executive
* @copydoc Trick::Executive::set_trap_sigsegv
* C wrapper for Trick::Executive::set_trap_sigsegv
*/
extern "C" int exec_set_trap_sigchld( int on_off ) {
if ( the_exec != NULL ) {
return the_exec->set_trap_sigchld((bool)on_off) ;
}
return -1 ;
}
/**
* @relates Trick::Executive
* @copydoc Trick::Executive::set_job_onoff

View File

@ -135,6 +135,32 @@ int Trick::Executive::set_trap_sigabrt(bool on_off) {
return(0) ;
}
/**
@details
-# If incoming on_off flag is true assign sig_hand() as the signal handler for SIGCHLD
-# Else revert to the default signal handler SIG_DFL.
-# set trap_sigabrt to the current on_off status
Requirement [@ref r_exec_signal_0].
*/
int Trick::Executive::set_trap_sigchld(bool on_off) {
static struct sigaction sigact;
if ( on_off ) {
/* Assign sig_hand() as the signal handler for SIGABRT */
sigact.sa_handler = (void (*)(int)) child_handler;
} else {
sigact.sa_handler = SIG_DFL;
}
if (sigaction(SIGCHLD, &sigact, NULL) < 0) {
perror("sigaction() failed for SIGCHLD");
} else {
trap_sigchld = on_off ;
}
return(0) ;
}
/**
@details
-# Catch SIGBUS, SIGSEGV, and SIGABRT errors. Don't catch SIGFPE
@ -149,11 +175,12 @@ int Trick::Executive::init_signal_handlers() {
static struct sigaction sigact;
/* By default catch SIGBUS and SIGSEGV. Don't catch SIGFPE */
/* By default catch SIGBUS, SIGSEGV, SIGABRT, and SIGCHLD. Don't catch SIGFPE */
set_trap_sigbus(true) ;
set_trap_sigfpe(false) ;
set_trap_sigsegv(true) ;
set_trap_sigabrt(true) ;
set_trap_sigchld(true) ;
/* Assign ctrl_c_hand() as the default signal handler for SIGINT (<CTRL-C> keypress). */
sigact.sa_handler = (void (*)(int)) ctrl_c_hand;
@ -173,12 +200,6 @@ int Trick::Executive::init_signal_handlers() {
perror("sigaction() failed for SIGUSR1");
}
/* Assign child_handler() as the default signal handler for SIGCHLD. */
sigact.sa_handler = (void (*)(int)) child_handler;
if (sigaction(SIGCHLD, &sigact, NULL) < 0) {
perror("sigaction() failed for SIGCHLD");
}
return(0) ;
}