Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use kqueue EVFILT_SIGNAL to support signals on BSD #116

Open
ids1024 opened this issue Nov 15, 2022 · 4 comments
Open

Use kqueue EVFILT_SIGNAL to support signals on BSD #116

ids1024 opened this issue Nov 15, 2022 · 4 comments

Comments

@ids1024
Copy link
Member

ids1024 commented Nov 15, 2022

The fact that signals are only supported on Linux is currently one of the issues using Smithay on BSDs. It looks like it should be possible to implement this with kqueue instead of signalfd, though I'm not currently familiar with kqueue.

@ids1024
Copy link
Member Author

ids1024 commented Nov 17, 2022

I guess for this to work, Kqueue needs a method for registering things other than fds, and Poll would need BSD/macOS specific methods wrapping it?

EVFILT_SIGNAL messages are sent after normal signal handling, even for SIG_IGN signals. So if the signal is set to SIG_IGN this should provide the same behavior that signalfd offers. (This is why BSD doesn't have things like signalfd; they aren't needed when kqueue exists.)

Or technically it's possible to poll a kqueue or insert it in another kqueue. So that might work with the current API but isn't exactly elegant.

@elinorbgr
Copy link
Member

elinorbgr commented Dec 19, 2022

I think an option would definitely be to handle signal handling in a way more tightly coupled to the internal Poll, like is currently done for timers.

Event sources provided in calloop are privileged, in that they can directly tap into the Poll logic, rather than only use the public API.

@ids1024
Copy link
Member Author

ids1024 commented Dec 19, 2022

Good point. This needn't result in any change to the public API (other than making the signal support available on BSD/macOS). It could be useful to have a public API for other kqueue filter types (seems handy for crate consumers targetting kqueue OSes).

Probably the awkward thing here is that subscribing to an EVFILT_SIGNAL won't block the signal. So we need to also use sigaction to ignore signals that would otherwise cause the process to terminate. This sort of global state is awkward, and could lead to inconsistent behavior with multiple event sources for the same signal. Or code outside calloop dealing with signal handlers. But I guess that shouldn't really happen, so it's not a problem as long as that isn't undefined behavior.

@notgull
Copy link
Member

notgull commented Jan 15, 2024

polling supports this via the Signal type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants