Skip to content

Commit

Permalink
Feature dtcenter/METplus-Internal#21 signal handling (#2336)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgemccabe authored Nov 9, 2022
1 parent e7f82bc commit 6b5567f
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/basic/vx_util/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ void do_pre_process(int argc, char *argv[]);
void set_handlers();
void set_user_id();
void store_arguments(int argc, char **argv);
void tidy_and_exit(int signal);

////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -124,7 +125,6 @@ string get_current_time() {

////////////////////////////////////////////////////////////////////////

/* not working at Docker
// based on blog at http://www.alexonlinux.com/how-to-handle-sigsegv-but-also-generate-core-dump
// NOTE: that comments on the blog indicate the core file generated on red hat or on multi-threaded programs
// might contain unhelpful information.
Expand All @@ -134,22 +134,23 @@ void segv_handler(int signum) {

getcwd(cwdbuffer,MET_BUF_SIZE+1);

fprintf(stderr, "FATAL ERROR (SEGFAULT): Process %d got signal %d @ local time = %s\n", getpid(), signum, timebuffer);
fprintf(stderr, "FATAL ERROR (SEGFAULT): Process %d got signal %d @ local time = %s\n", getpid(), signum, timebuffer.c_str());
fprintf(stderr, "FATAL ERROR (SEGFAULT): Look for a core file in %s\n",cwdbuffer);
fprintf(stderr, "FATAL ERROR (SEGFAULT): Process command line: %s\n",met_cmdline.c_str());
signal(signum, SIG_DFL);
kill(getpid(), signum);
}
*/

////////////////////////////////////////////////////////////////////////
// Need signal handlers for SIGINT, SIGHUP, SIGTERM, SIGPIPE, and SIGSEGV
// PORTsignal(SIGPIPE, (PORTsigfunc)SIG_IGN);
// PORTsignal(SIGSEGV, segv_handler);

void set_handlers() {

set_new_handler(oom);
set_new_handler(oom);
signal(SIGSEGV, segv_handler);
signal(SIGINT, tidy_and_exit);
signal(SIGTERM, tidy_and_exit);
signal(SIGABRT, tidy_and_exit);
signal(SIGFPE, tidy_and_exit);
signal(SIGILL, tidy_and_exit);
}

////////////////////////////////////////////////////////////////////////
Expand All @@ -173,6 +174,18 @@ void store_arguments(int argc, char **argv) {
////////////////////////////////////////////////////////////////////////

void tidy_and_exit(int signal) {
printf("FATAL: ");
if(signal == SIGINT) {
printf("Received Signal Interrupt. ");
} else if(signal == SIGTERM){
printf("Received Signal Terminate. ");
} else if(signal == SIGABRT){
printf("Received Signal Abort. ");
} else if(signal == SIGFPE){
printf("Received Signal Floating-Point Exception. ");
} else if(signal == SIGILL){
printf("Received Signal Illegal Instruction. ");
}
printf("Exiting %d\n", signal);
exit(signal);
}
Expand Down

0 comments on commit 6b5567f

Please sign in to comment.