[Interest] Connecting signal handler to Qt application - async-handler-safety

Thiago Macieira thiago.macieira at intel.com
Mon Jun 15 18:11:07 CEST 2020


On segunda-feira, 15 de junho de 2020 03:58:12 PDT Bernhard Lindner wrote:
> I wrote a logging application containing a signal handler that is registered
> using std::signal(). The handler receives signals like SIGFPE, SIGSEGV,
> etc.
> 
> Now I would like to connect that handler to some Qt based logging code.
> Unfortunately I could not find a portable solution to do that.
> 
> Are there any functions in Qt that are considered async-handler-safe?

Absolutely none. Please restrict your use in the signal handler to only the 
functions listed here:
https://man7.org/linux/man-pages/man7/signal-safety.7.html

> I'm especially looking for a way to send a (queued) signal. Other portable
> ways to wake the application from the event loop would be fine as well.

The simplest solution for this is to write some from the signal handler 
information to a pipe. It can be just a single byte to wake up the event loop. 
Then the main Qt event loop will pick that up via QSocketNotifier and act 
accordingly.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel System Software Products





More information about the Interest mailing list