From 55a4d35dc3e7da9686727469fb6fbf2e516ddd4b Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 2 May 2022 19:50:07 -0700 Subject: [PATCH] FatalSignalHandler: remove call to qEnvironmentXxx from handler code The Qt environment handling functions lock a mutex. That's a big no-no in signal handlers. [ChangeLog][QtTest][Behavior Change] QtTest will now check the value of the environment variable QTEST_PAUSE_ON_CRASH in QTest::qRun(), so if a test wants to modify this variable, it must do so from the main() or initMain() functions, not in the test itself (including initTestCase()). Pick-to: 6.3 Change-Id: I5ff8e16fcdcb4ffd9ab6fffd16eb78867cd8f54e Reviewed-by: Marc Mutz --- src/testlib/qtestcase.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index 43facebe58f..904c007594e 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -1782,6 +1782,7 @@ public: SetErrorMode(SetErrorMode(0) | SEM_NOGPFAULTERRORBOX); SetUnhandledExceptionFilter(windowsFaultHandler); #elif defined(Q_OS_UNIX) && !defined(Q_OS_WASM) + pauseOnCrash = qEnvironmentVariableIsSet("QTEST_PAUSE_ON_CRASH"); sigemptyset(&handledSignals); const int fatalSignals[] = { @@ -1940,7 +1941,7 @@ private: const int msecsTotalTime = qRound(QTestLog::msecsTotalTime()); if (signum != SIGINT) { generateStackTrace(); - if (qEnvironmentVariableIsSet("QTEST_PAUSE_ON_CRASH")) { + if (pauseOnCrash) { writeToStderr("Pausing process ", asyncSafeToString(getpid()), " for debugging\n"); raise(SIGSTOP); @@ -1962,8 +1963,12 @@ private: } sigset_t handledSignals; + static bool pauseOnCrash; #endif // defined(Q_OS_UNIX) && !defined(Q_OS_WASM) }; +#if defined(Q_OS_UNIX) && !defined(Q_OS_WASM) +bool FatalSignalHandler::pauseOnCrash = false; +#endif // defined(Q_OS_UNIX) && !defined(Q_OS_WASM) } // namespace