Skip to content

Commit

Permalink
Check for sighandler_t and redifine only if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
joakim-hove authored and Andrea Brambilla committed Jul 5, 2019
1 parent 56f1330 commit e6d0253
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ try_compile( HAVE_SIGBUS ${CMAKE_BINARY_DIR} ${PROJECT_SOURCE_DIR}/cmake/Tests/
try_compile( HAVE_PID_T ${CMAKE_BINARY_DIR} ${PROJECT_SOURCE_DIR}/cmake/Tests/test_pid_t.c )
try_compile( HAVE_MODE_T ${CMAKE_BINARY_DIR} ${PROJECT_SOURCE_DIR}/cmake/Tests/test_mode_t.c )
try_compile( ERT_HAVE_ISFINITE ${CMAKE_BINARY_DIR} ${PROJECT_SOURCE_DIR}/cmake/Tests/test_isfinite.c)
try_compile( HAVE_SIGHANDLER_T ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR}/cmake/Tests/test_have_sighandler.c)

if (ERT_HAVE_READLINKAT)
try_compile( ERT_HAVE_READLINKAT_DECLARATION
Expand Down
6 changes: 6 additions & 0 deletions cmake/Tests/test_have_sighandler.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <signal.h>


void main(int argc, char *argv[]) {
sighandler_t my_handler = SIG_IGN;
}
2 changes: 1 addition & 1 deletion lib/build_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#cmakedefine HAVE_CXX_SHARED_PTR
#cmakedefine HAVE_POSIX_UNLINK
#cmakedefine HAVE_WINDOWS_UNLINK

#cmakedefine HAVE_SIGHANDLER_T

#cmakedefine HAVE_POSIX_ACCESS
#cmakedefine HAVE_WINDOWS__ACCESS
Expand Down
8 changes: 0 additions & 8 deletions lib/include/ert/util/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <stdarg.h>
#include <sys/types.h>
#include <time.h>
#include <signal.h>


#include <ert/util/ert_api_config.hpp>
Expand Down Expand Up @@ -388,13 +387,6 @@ typedef bool (walk_dir_callback_ftype) (const char * , /* The current director
CONTAINS_HEADER(size_t);
#undef CONTAINS_HEADER

/* Redefining sighandler_t in case it isn't defined (Windows).
This is harmless on other platforms. */
typedef void (*sighandler_t)(int);
/* When installing our abort handler, remeber if there was a previous one,
* so we can call that afterwards */
extern sighandler_t previous_abort_handler;

#ifdef _MSC_VER
#define util_abort(fmt , ...) util_abort__(__FILE__ , __func__ , __LINE__ , fmt , __VA_ARGS__)
#elif __GNUC__
Expand Down
12 changes: 11 additions & 1 deletion lib/util/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -4405,7 +4405,17 @@ char * util_realloc_sprintf(char * s , const char * fmt , ...) {
The various signals can be found in: /usr/include/bits/signum.h
*/

sighandler_t previous_abort_handler = SIG_IGN;
/* Redefining sighandler_t in case it isn't defined (Windows).*/

#ifndef HAVE_SIGHANDLER_T
typedef void (*sighandler_t)(int);
#endif

/* When installing our abort handler, remeber if there was a previous one,
* so we can call that afterwards */


static sighandler_t previous_abort_handler = SIG_IGN;

void util_abort_signal(int the_signal) {
if (previous_abort_handler == SIG_IGN) {
Expand Down

0 comments on commit e6d0253

Please sign in to comment.