diff --git a/hphp/runtime/ext/ext_process.cpp b/hphp/runtime/ext/ext_process.cpp index fc671e973..bedc69f3a 100644 --- a/hphp/runtime/ext/ext_process.cpp +++ b/hphp/runtime/ext/ext_process.cpp @@ -20,6 +20,7 @@ #include "hphp/runtime/ext/ext_function.h" #include "hphp/runtime/base/string_buffer.h" #include "hphp/runtime/base/zend_string.h" +#include "hphp/runtime/base/thread_init_fini.h" #include #include #include @@ -281,6 +282,16 @@ public: }; IMPLEMENT_STATIC_REQUEST_LOCAL(SignalHandlers, s_signal_handlers); +// We must register the s_signal_handlers RequestEventHandler +// immediately: otherwise, pcntl_signal_handler might try to register +// it while processing a signal, which means calling malloc to insert +// it into various vectors and sets, which is not ok from a signal +// handler. +const InitFiniNode initSignalHandler( + [] { s_signal_handlers.get(); }, + InitFiniNode::When::ThreadInit +); + static void pcntl_signal_handler(int signo) { if (signo > 0 && signo < _NSIG && !g_context.isNull()) { s_signal_handlers->signaled[signo] = 1;