GNOME Bugzilla – Bug 704322
glib-unix: fix handling of multiple signal source for the same signal
Last modified: 2013-10-29 17:52:26 UTC
We can't reset the pending flag for a signal until we've traversed the whole list, as the documentation clearly says that in case multiple sources they all get invoked. This is still racy if you get a signal after checking the flag but before resetting it, but it was the same before. The correct fix would be to use sigwait() or signalfd(), but that would mean blocking all signals in all threads, which is not compatible with existing applications.
Created attachment 249272 [details] [review] glib-unix: fix handling of multiple signal source for the same signal
Where do the docs say that an incoming unix signal is delivered to all of the sources for that signal?
Note that unlike the UNIX default, all sources which have created a watch will be dispatched, regardless of which underlying thread invoked g_unix_signal_source_new(). From the docs for g_unix_signal_source_new()
To me this speaks to the question of which thread signals will be processed in rather than having multiple instances of handlers. Clearly it never worked that way before, so the code doesn't match your reading of the docs. Why do you want multiple handlers?
(In reply to comment #4) > To me this speaks to the question of which thread signals will be processed in > rather than having multiple instances of handlers. Clearly it never worked > that way before, so the code doesn't match your reading of the docs. That was my original intention...looks like I got it wrong. > Why do you want multiple handlers? It wouldn't seem totally crazy to me for a library (sufficiently documented) to register a SIGTERM handler for cleanup. I dunno, there's also the situation where your application just grows over time and you end up with two SIGTERM/SIGINT handlers just in your app. Having to refactor to hoist things to the toplevel can be a pain.
Review of attachment 249272 [details] [review]: This code looks good. ::: glib/tests/unix.c @@ +137,3 @@ + + kill (getpid (), signum); + g_main_loop_run (mainloop); The new idiomatic mainloop code here would be: while (sig_counter != 2) g_main_context_iteration (NULL); Up to you if you want to convert though.
Attachment 249272 [details] pushed as be2c7b8 - glib-unix: fix handling of multiple signal source for the same signal I don't want to rewrite the existing test cases, and for consistency I left the new one as is.
This caused bug 711090.