Qt 4.8
Public Functions | Static Private Functions | Properties | List of all members
QTest::FatalSignalHandler Class Reference

Public Functions

 FatalSignalHandler ()
 
 ~FatalSignalHandler ()
 

Static Private Functions

static void signal (int)
 

Properties

sigset_t handledSignals
 

Detailed Description

Definition at line 1788 of file qtestcase.cpp.

Constructors and Destructors

◆ FatalSignalHandler()

QTest::FatalSignalHandler::FatalSignalHandler ( )

Definition at line 1812 of file qtestcase.cpp.

1813 {
1814  sigemptyset(&handledSignals);
1815 
1816  const int fatalSignals[] = {
1817  SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGFPE, SIGSEGV, SIGPIPE, SIGTERM, 0 };
1818 
1819  struct sigaction act;
1820  memset(&act, 0, sizeof(act));
1821  act.sa_handler = FatalSignalHandler::signal;
1822 
1823  // Remove the handler after it is invoked.
1824 #if !defined(Q_OS_INTEGRITY)
1825  act.sa_flags = SA_RESETHAND;
1826 #endif
1827  // Block all fatal signals in our signal handler so we don't try to close
1828  // the testlog twice.
1829  sigemptyset(&act.sa_mask);
1830  for (int i = 0; fatalSignals[i]; ++i)
1831  sigaddset(&act.sa_mask, fatalSignals[i]);
1832 
1833  struct sigaction oldact;
1834 
1835  for (int i = 0; fatalSignals[i]; ++i) {
1836  sigaction(fatalSignals[i], &act, &oldact);
1837 #ifndef Q_WS_QWS
1838  // Don't overwrite any non-default handlers
1839  // however, we need to replace the default QWS handlers
1840  if (
1841 #ifdef SA_SIGINFO
1842  oldact.sa_flags & SA_SIGINFO ||
1843 #endif
1844  oldact.sa_handler != SIG_DFL) {
1845  sigaction(fatalSignals[i], &oldact, 0);
1846  } else
1847 #endif
1848  {
1849  sigaddset(&handledSignals, fatalSignals[i]);
1850  }
1851  }
1852 }
int sigaction(int, const struct sigaction *, struct sigaction *)
static void signal(int)
Definition: qtestcase.cpp:1799

◆ ~FatalSignalHandler()

QTest::FatalSignalHandler::~FatalSignalHandler ( )

Definition at line 1855 of file qtestcase.cpp.

1856 {
1857  // Unregister any of our remaining signal handlers
1858  struct sigaction act;
1859  memset(&act, 0, sizeof(act));
1860  act.sa_handler = SIG_DFL;
1861 
1862  struct sigaction oldact;
1863 
1864  for (int i = 1; i < 32; ++i) {
1865  if (!sigismember(&handledSignals, i))
1866  continue;
1867  sigaction(i, &act, &oldact);
1868 
1869  // If someone overwrote it in the mean time, put it back
1870  if (oldact.sa_handler != FatalSignalHandler::signal)
1871  sigaction(i, &oldact, 0);
1872  }
1873 }
int sigaction(int, const struct sigaction *, struct sigaction *)
static void signal(int)
Definition: qtestcase.cpp:1799

Functions

◆ signal()

void QTest::FatalSignalHandler::signal ( int  signum)
staticprivate

Definition at line 1799 of file qtestcase.cpp.

Referenced by FatalSignalHandler(), and ~FatalSignalHandler().

1800 {
1801  qFatal("Received signal %d", signum);
1802 #if defined(Q_OS_INTEGRITY)
1803  {
1804  struct sigaction act;
1805  memset(&act, 0, sizeof(struct sigaction));
1806  act.sa_handler = SIG_DFL;
1807  sigaction(signum, &act, NULL);
1808  }
1809 #endif
1810 }
Q_CORE_EXPORT void qFatal(const char *,...)
int sigaction(int, const struct sigaction *, struct sigaction *)

Properties

◆ handledSignals

sigset_t QTest::FatalSignalHandler::handledSignals
private

Definition at line 1796 of file qtestcase.cpp.


The documentation for this class was generated from the following file: