On Sun, Sep 26, 2021 at 02:36:02PM +0200, Mark Kettenis wrote:
> > Date: Fri, 24 Sep 2021 19:36:21 +0200
> > From: Rafael Sadowski <raf...@sizeofvoid.org>
> > 
> > I'm trying to port the more KDE stuff so my question is from porter
> > perspective.
> > 
> > I need sigwaitinfo(2)/sigtimedwait(2) and I found both functions in
> > lib/libc/gen/sigwait.c with the comment "need kernel to fill in more
> > siginfo_t bits first". Is the comment still up to date? If no, is it
> > possible to unlock the functions?
> 
> Still true.  These functions are somewhat underspecified by POSIX so
> it isn't really obvious whatadditional bits need to be filled in.
> Having examples of code that use these interfaces from ports could
> help with that.

Not in ports, but in a Lua Unix bindings module I ended up writing an
incomplete sigtimedwait emulation for OpenBSD and macOS targets. It's not
thread-safe and lacks siginfo support, but sufficed for the most pressing
use case, which was to provide a standard (non-kqueue, non-signalfd), simple
(i.e. robust to subtle race conditions that might leave a process hung or
drop a signal on the floor) mechanism to receive and *clear* signals in Lua
code without having to deal with catching and invoking signal handlers
asynchronously in Lua or otherwise writing some complex, fiddly mechanism
for bridging the language and runtime divide.

By emulating sigtimedwait I in fact ended up writing a fiddly and incomplete
mechanism for bridging C and Lua runtime behaviors, but only because
sigtimedwait didn't exist on OpenBSD or macOS; from the perspective of Lua
code relying on POSIX APIs, it still made sense.

At least in my case a sigtimedwait lacking siginfo support would have been
infinitely better than no sigtimedwait at all. It's the ability to clear a
signal without using a signal handler, while also being able to specify a
timeout so you don't accidentally end up hung in sigwait, that was most
important. Technically sigpending+sigwait would suffice for non-blocking
polling (potential thread races notwithstanding), but when looking at POSIX
APIs sigtimedwait is the most obvious solution for that as well as some more
complex scenarios.

Reply via email to