Skip to main content

Timeline for answer to Safely and elegantly handling UNIX signals in Qt applications by Toby Speight

Current License: CC BY-SA 3.0

Post Revisions

14 events
when toggle format what by license comment
May 5, 2022 at 16:47 comment added Toby Speight You're quite right - that qWarning() is dangerous there. I need to go back and fix that!
May 5, 2022 at 15:52 comment added Zoltan K. I would not use qWarning(), or anything Qt in a signal handler. It is implementation-dependent, if it happens to be safe or not. It may use threads, synchronization objects, whatever else that can go wrong.
Dec 7, 2020 at 21:34 comment added Fritz No the project this was developed for was canceled eventually, and I didn't get around to composing it in my spare time. If I ever do, I will post it here for sure, because I think it's genuinely useful.
Dec 4, 2020 at 11:55 comment added Toby Speight @Fritz, did you ever write the combined implementation? If so, consider posting as a new question.
Aug 29, 2019 at 12:35 vote accept Fritz
Sep 8, 2017 at 17:19 comment added Fritz I'll try to write a combined implementation during the weekend, including multiplexing and your other remarks, and post that as a separate answer. You're welcome to do so too and see if you're faster though. :)
Sep 8, 2017 at 17:15 comment added Fritz Yep, using UCHAR_MAX was also my thought when considering multiplexing. That's probably enough signals for any UNIX system in existence. If you multiplex, there's also no need to do an array lookup inside the unix signal handler, like my implementation does, it's just a single write. So we could maybe save a few bytes of memory by using a QMap<int,UnixSignalHandler*> instead of UnixSignalHandler array[UCHAR_MAX]. I'm not sure how much RAM a map actually uses, though...
Sep 8, 2017 at 16:32 history edited Toby Speight CC BY-SA 3.0
Explain how the array manages itself
Sep 8, 2017 at 16:30 comment added Toby Speight Agreed with everything. Taking the points in sequence: The array does act as a singleton, as you say. I was re-reading your code as you wrote the comment, and updated my answer when I saw you also use one pipe per signal. My needs were only for the traditional Unix signals, so I was content to stop there. UCHAR_MAX would be another choice, if we multiplex onto a single pipe (in theory, we can't guarantee a complete write of more than one char).
Sep 8, 2017 at 16:22 history edited Toby Speight CC BY-SA 3.0
Further observations; also, the QPointer obviates the cleanup of handler array
Sep 8, 2017 at 16:21 comment added Fritz Ah, using one object per signal is a clever idea, and obvious in hindsight. I really, really need to get those singletons patterns out of my head. However, we still need a static (and thus singleton) data structure to hold the individual objects, like your std::array Also, my implementation doesn't do multiplexing on the pipe, meaning it also consumes two FDs per signal, just like yours. But that's also a really good idea and pretty easy to change. :) _NSIG is probably an artifact and I shouldn't use it because of the underscore. However, your limit of 32 doesn't include RT signals.
Sep 8, 2017 at 16:21 history edited Toby Speight CC BY-SA 3.0
Further observations
Sep 8, 2017 at 16:14 history edited Toby Speight CC BY-SA 3.0
added 32 characters in body
Sep 8, 2017 at 16:07 history answered Toby Speight CC BY-SA 3.0