From 4e19bb8f08fae00a7700f2f8e9dbaeb3607d739b Mon Sep 17 00:00:00 2001 From: Frank Liu Date: Tue, 15 Jan 2019 11:04:42 -0800 Subject: [PATCH] Avoid adding SegfaultLogger if process already has sig handler. (#13842) In current implemenation, we override signal handler regardless if MXNET_USE_SIGNAL_HANDLER=1. This breaks caller process behavior and cause process exit unexpectedly. The example use case is libmxnet.so is loadded into java process via JNI or JNA. JVM will crash due to SegfaultLogger. In this PR, we will not register SegfaultLogger if there is a signal handler registered. --- src/initialize.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/initialize.cc b/src/initialize.cc index de7edd1b1455..8d0e3c304216 100644 --- a/src/initialize.cc +++ b/src/initialize.cc @@ -44,7 +44,11 @@ class LibraryInitializer { LibraryInitializer() { dmlc::InitLogging("mxnet"); #if MXNET_USE_SIGNAL_HANDLER && DMLC_LOG_STACK_TRACE - signal(SIGSEGV, SegfaultLogger); + struct sigaction sa; + sigaction(SIGSEGV, NULL, &sa); + if (sa.sa_handler == NULL) { + signal(SIGSEGV, SegfaultLogger); + } #endif // disable openmp for multithreaded workers