User: Password:
|
|
Subscribe / Log in / New account

signals without signal stacks

signals without signal stacks

Posted Mar 15, 2007 15:31 UTC (Thu) by pjones (subscriber, #31722)
In reply to: Kernel events without kevents by pphaneuf
Parent article: Kernel events without kevents

It's better than that - with signalfd(), you can use e.g. malloc(), printf(), and backtrace() while handling a signal.

That's really a huge win. It'll also mean things like Xorg won't need to inject crap like VT_CHANGE handling into its event loop from a signal handler.


(Log in to post comments)

signals without signal stacks

Posted Mar 15, 2007 15:43 UTC (Thu) by pphaneuf (subscriber, #23480) [Link]

You could do malloc() and printf() with the "write a byte on a pipe in the signal handler" trick, but backtrace()? It won't be like doing it from a signal handler, it'll just give the stack trace of where you read() from the signal handler fd, no? That, again, would be just like the pipe trick.

Not that it's not neat, it saves a whole lot of coding, having to save things on the side so you can look at them later, but it basically operates the same way. I didn't focus on those very much, because handling signals in a library, through the pipe trick or not, is just a bad idea, IMHO (the application hooks the same signal, and then everything goes to hell in a handbasket).

But the timer is something that didn't really need coordination with an application (from the point of view of a library), but had to, because, well, that's the way it was. I had some idiotic tricks that worked, but were just disgusting (a thread started from my library to handle timers and write to a pipe to wake up the main loop, eww!). Well, not anymore!

signals without signal stacks

Posted Mar 15, 2007 16:11 UTC (Thu) by pjones (subscriber, #31722) [Link]

Well, it's not _always_ a bad idea. Consider the SIGPIPE vs db4 problem. If you have a library using both db4 and a network, you sometimes need to block signals - but you still want them to be raised to the caller. With signalfd(), you can do a fairly simple callback system sanely, which you really can't do as cleanly with the old-style signal/sigaction interfaces.

(yeah, arguably you can raise(), but you still have to have a doesn't-do-much signal handler deep in a library, which can get really ugly really fast)


Copyright © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds