diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2021-11-16 19:22:40 +0100 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2021-11-18 18:13:20 +0100 |
commit | 2ad5fd36fb0b77040113e93323911fbd5c3ccb49 (patch) | |
tree | ece89a3618b1d9b88cffb8b996811f6ab7cf0ae4 /src/testlib/qtestcase.cpp | |
parent | 771657e55f66c354e9e4ee682e6a0bd259521e06 (diff) |
Rework FatalSignalHandler to use ranged-for loops over signals
Shrinks the const array by one zero-terminator and makes the code
accessing it read more gracefully.
Change-Id: I4034116a83ff3cd05ea0feb0ce8a4340c54a9faa
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/testlib/qtestcase.cpp')
-rw-r--r-- | src/testlib/qtestcase.cpp | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index 79191861b1..4cb9067c69 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -1670,7 +1670,7 @@ public: sigemptyset(&handledSignals); const int fatalSignals[] = { - SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGBUS, SIGFPE, SIGSEGV, SIGPIPE, SIGTERM, 0 }; + SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGBUS, SIGFPE, SIGSEGV, SIGPIPE, SIGTERM }; struct sigaction act; memset(&act, 0, sizeof(act)); @@ -1703,8 +1703,8 @@ public: // Block all fatal signals in our signal handler so we don't try to close // the testlog twice. sigemptyset(&act.sa_mask); - for (int i = 0; fatalSignals[i]; ++i) - sigaddset(&act.sa_mask, fatalSignals[i]); + for (int sig : fatalSignals) + sigaddset(&act.sa_mask, sig); // The destructor can only restore SIG_DFL, so only register for signals // that had default handling previously. @@ -1720,14 +1720,14 @@ public: }; struct sigaction oldact; - for (int i = 0; fatalSignals[i]; ++i) { + for (int sig : fatalSignals) { // Registering reveals the existing handler: - if (sigaction(fatalSignals[i], &act, &oldact)) + if (sigaction(sig, &act, &oldact)) continue; // Failed to set our handler; nothing to restore. if (isDefaultHandler(oldact)) - sigaddset(&handledSignals, fatalSignals[i]); + sigaddset(&handledSignals, sig); else // Restore non-default handler: - sigaction(fatalSignals[i], &oldact, nullptr); + sigaction(sig, &oldact, nullptr); } #endif // defined(Q_OS_UNIX) && !defined(Q_OS_WASM) } |