From f1ba15de0a965b613028c574c2d3f7bb035c8b31 Mon Sep 17 00:00:00 2001 From: AdamSimpson Date: Mon, 9 Nov 2015 14:42:02 -0500 Subject: [PATCH] Remove signal handler recursive call potential --- src/split.c | 36 +++++++++++++++++++++++------------- wraprun_formula.rb | 2 +- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/split.c b/src/split.c index a098922..afaa41a 100644 --- a/src/split.c +++ b/src/split.c @@ -138,18 +138,24 @@ static void CloseStdOutErr() { } // Wait for all other wraprun processes to complete before exiting -// Calling PMPI_Finalize and fprintf is undefined +// Calling MPI_Finalize and fprintf is undefined // Cleanup operations have been problematic so are skipped static void SegvHandler(int sig) { - PMPI_Finalize(); + // If the process receives another SEGV throw in the towel + signal(SIGSEGV, SIG_DFL); - fprintf(stderr, "*********\n ERROR: Signal Received: %d\n*********\n", sig); + fprintf(stderr, "*********\n ERROR: Signal SEGV Received\n*********\n"); + + MPI_Finalize(); _exit(EXIT_SUCCESS); } // Handle SIGABRT, to handle a call to abort() for instance static void AbrtHandler(int sig) { + // If the process receives another ABRT throw in the towel + signal(SIGABRT, SIG_DFL); + fprintf(stderr, "*********\n ERROR: Signal Received: %d\n*********\n", sig); MPI_Finalize(); @@ -260,16 +266,20 @@ int MPI_Finalize() { EXIT_PRINT("Failed to free split communicator: %d !\n", err); } - // Allow MPI_Finalize to be called directly - int return_value; - if (getenv("W_UNWRAP_FINALIZE")) { - DEBUG_PRINT("Unwrapped!\n"); - int (*real_MPI_Finalize)() = dlsym(RTLD_NEXT, "MPI_Finalize"); - return_value = (*real_MPI_Finalize)(); - } - else { - DEBUG_PRINT("Wrapped!\n"); - return_value = PMPI_Finalize(); + int return_value = 0; + int finalized = 0; + MPI_Finalized(&finalized); + if(!finalized) { + // Allow MPI_Finalize to be called directly + if (getenv("W_UNWRAP_FINALIZE")) { + DEBUG_PRINT("Unwrapped!\n"); + int (*real_MPI_Finalize)() = dlsym(RTLD_NEXT, "MPI_Finalize"); + return_value = (*real_MPI_Finalize)(); + } + else { + DEBUG_PRINT("Wrapped!\n"); + return_value = PMPI_Finalize(); + } } if (getenv("W_REDIRECT_OUTERR")) diff --git a/wraprun_formula.rb b/wraprun_formula.rb index 3a41a5d..24c7ca5 100644 --- a/wraprun_formula.rb +++ b/wraprun_formula.rb @@ -1,6 +1,6 @@ class WraprunFormula < Formula homepage "https://github.com/olcf/wraprun" - url "https://github.com/olcf/wraprun/archive/v0.1.6.tar.gz" + url "https://github.com/olcf/wraprun/archive/v0.1.7.tar.gz" concern for_version("dev") do included do