Fix bad signal restoration which can cause infinite loop

This fix the FatalSignalHandler destructor to restore properly the
signal handler which cause an infinite loop when a signal is emitted
like SIGABRT or SIGINT and when we are using two QTest object in same
program.

Fixes: QTBUG-132121
Pick-to: 6.8 6.5
Change-Id: Ie9476e1ff9c0f29c3e35ae6dff565fab4a77ba86
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit 50d1a22e5c6361e7c1ef09432b2a151eee3e6114)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Eric Beuque 2025-02-17 17:45:51 +01:00 committed by Qt Cherry-pick Bot
parent 73e9605765
commit dcf09c0c63

View File

@ -548,10 +548,10 @@ FatalSignalHandler::~FatalSignalHandler()
for (size_t i = 0; i < fatalSignals.size(); ++i) {
struct sigaction &act = oldActions()[i];
if (act.sa_flags == 0 && act.sa_handler == SIG_DFL)
continue; // Already the default
if (sigaction(fatalSignals[i], nullptr, &action))
continue; // Failed to query present handler
if (action.sa_flags == 0 && action.sa_handler == SIG_DFL)
continue; // Already the default
if (isOurs(action))
sigaction(fatalSignals[i], &act, nullptr);
}