Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature dtcenter/METplus-Internal#21 signal handling #2336

Merged
merged 1 commit into from
Nov 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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