util.signal: Wrap signalfd in an userdatum for gc handling etc

This commit is contained in:
Kim Alvefur 2024-02-24 01:00:44 +01:00
parent 49c296360d
commit 761643abcc
2 changed files with 63 additions and 9 deletions

View file

@ -1147,12 +1147,13 @@ end
local hook_signal;
if have_signal and signal.signalfd then
local function dispatch(self)
return self:on("signal", signal.signalfd_read(self:getfd()));
return self:on("signal", self.conn:read());
end
function hook_signal(signum, cb)
local watch = watchfd(signal.signalfd(signum), dispatch);
watch.listeners = { onsignal = cb };
watch.close = nil; -- revert to default
return watch;
end
end