From 8304310fd7228496cbef1ffcbd50e50f24e1a8e0 Mon Sep 17 00:00:00 2001 From: Frank Liu Date: Thu, 10 Jan 2019 15:57:09 -0800 Subject: [PATCH] Avoid adding SegfaultLogger if process already has sig handler. 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