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 <marc.mutz@qt.io>
This commit is contained in:
Thiago Macieira 2022-05-02 19:50:07 -07:00
parent c8d9b7291a
commit 55a4d35dc3

View File

@ -1782,6 +1782,7 @@ public:
SetErrorMode(SetErrorMode(0) | SEM_NOGPFAULTERRORBOX); SetErrorMode(SetErrorMode(0) | SEM_NOGPFAULTERRORBOX);
SetUnhandledExceptionFilter(windowsFaultHandler); SetUnhandledExceptionFilter(windowsFaultHandler);
#elif defined(Q_OS_UNIX) && !defined(Q_OS_WASM) #elif defined(Q_OS_UNIX) && !defined(Q_OS_WASM)
pauseOnCrash = qEnvironmentVariableIsSet("QTEST_PAUSE_ON_CRASH");
sigemptyset(&handledSignals); sigemptyset(&handledSignals);
const int fatalSignals[] = { const int fatalSignals[] = {
@ -1940,7 +1941,7 @@ private:
const int msecsTotalTime = qRound(QTestLog::msecsTotalTime()); const int msecsTotalTime = qRound(QTestLog::msecsTotalTime());
if (signum != SIGINT) { if (signum != SIGINT) {
generateStackTrace(); generateStackTrace();
if (qEnvironmentVariableIsSet("QTEST_PAUSE_ON_CRASH")) { if (pauseOnCrash) {
writeToStderr("Pausing process ", asyncSafeToString(getpid()), writeToStderr("Pausing process ", asyncSafeToString(getpid()),
" for debugging\n"); " for debugging\n");
raise(SIGSTOP); raise(SIGSTOP);
@ -1962,8 +1963,12 @@ private:
} }
sigset_t handledSignals; sigset_t handledSignals;
static bool pauseOnCrash;
#endif // defined(Q_OS_UNIX) && !defined(Q_OS_WASM) #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 } // namespace