[Interest] RFC: Unix signal convenience class

Alejandro Exojo aexojo at modpow.es
Thu Jan 30 16:12:56 CET 2014


In the Qt documentation there is a page explaining how to use a pair
of sockets for handling a Unix signal and end up triggering a Qt
signal. However, being a noob, it always seemed to me like a bit
complex. There is a (IMHO, really nice) presentation called "Qt for
non graphical applications" by Thomas Petazzoni, where there is an
example of how to do it in a different way (a bit more clear to me),
and wrapped in a class:

https://archive.fosdem.org/2012/schedule/event/700/132_qt-for-non-graphical-apps.pdf#35

I've grabbed that code, filled the gaps to make it compile, and
replaced sigprocmask() with pthread_sigmask() because the
documentation says "The use of sigprocmask() is unspecified in a
multithreaded process; see pthread_sigmask(3).". I've read the
documentation carefully, but I still barely know if what I'm doing can
bite me in the future, but for now I can say that it _seems_ to work
fine, but that might be because I'm not doing anything fancy with
threads or processes yet, and in the slot that is triggered indirectly
from the Unix signal I'm doing really simple things. But I fear there
might be a race condition.

Here is the code:

https://gist.github.com/suy/8706936

If someone has done something similar in the past, I would really
thank his/her opinion. I fear that such approach is wrong because as
said in the signal(7) manual page, only a small amount of low level
function calls are safe. And in the searching I've done, people said
"don't call _any_ Qt function from a Unix signal handler" (emphasis
mine):

http://comments.gmane.org/gmane.comp.lib.qt.general/39213

I suppose the convoluted use of a pair of sockets in the Qt
documentation is because something really really low level like a
::write() is the only simple thing that can be done in the signal
handler. Not even emitting queued signals or calling thread-safe
functions is safe there.

Comments?

Thank you very much!

PS: Is worth reporting it as a feature request in Qt? I fear that
since is very platform specific, its only place might be a Qt Unix
Extras module, and a module/library for only one small class is weird.
:)

-- 
Alejandro Exojo Piqueras

ModpoW, S.L.
Technova LaSalle | Sant Joan de la Salle 42 | 08022 Barcelona | www.modpow.es



More information about the Interest mailing list