[Interest] proper (silent) exit in response to SIGHUP?

Thiago Macieira thiago.macieira at intel.com
Sun Oct 7 20:00:48 CEST 2018

On Sunday, 7 October 2018 00:48:01 PDT René J.V. Bertin wrote:
> Hi,
> How feasible would it be to implement a SIGHUP handler that triggers a
> proper, silent/non-interactive exit?

It's not very difficult.

Open a pipe or an eventfd, then install your signal handler. In that signal 
handler, write anything to the writing end or write uint64_t(1) the eventfd. 
Create a QSocketNotifier on the reading end of the pipe or on the eventfd, 
connect its activation signal to a slot that does what you want.

That's it.

> I presume the problem isn't very hard for applications running locally
> (though I might be overlooking something). However, I mostly have the XCB
> QPA in mind here, and applications running remotely on an X11 server that
> becomes unresponsive or unavailable (network issue, or remote host
> suspended). Does the regular shutdown procedure under X11 contain calls
> that would block indefinitely and if so, is there a way to circumvent this
> procedure (calling exit() or _exit() after some custom save-what-you-can
> cleanup)? I'd presume that similar interrogations can be made for other
> QPAs allowing remote displaying - the VNC QPA and possibly Wayland?

Exiting with exit() is not expected to work with Qt. Normal exit must return 
from main(), so you should simply ask the QCoreApplication main event loop to 
exit (quit() slot).

_exit() is a valid alternative, but note it won't save any files or flush any 
buffers or run destructors.

But if you wanted that, you wouldn't need to add a signal handler, since 
SIGHUP's default behaviour is to terminate the application.

Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center

More information about the Interest mailing list