# HG changeset patch # User Kim Alvefur # Date 1708730435 -3600 # Node ID b27de3d2bad61f1d21e30458f20f5cc1680bdea2 # Parent 1e229d710a3c872926b740511f87c8864bf28944 net.server_epoll: Support hooking signals via signalfd Handling signal events the same way as all other events makes sense and seems safer than the signal handling just jumping around in C and messing with Lua states. diff -r 1e229d710a3c -r b27de3d2bad6 net/server_epoll.lua --- a/net/server_epoll.lua Sat Feb 24 00:05:29 2024 +0100 +++ b/net/server_epoll.lua Sat Feb 24 00:20:35 2024 +0100 @@ -29,6 +29,7 @@ local xpcall = require "prosody.util.xpcall".xpcall; local sslconfig = require "prosody.util.sslconfig"; local tls_impl = require "prosody.net.tls_luasec"; +local have_signal, signal = pcall(require, "prosody.util.signal"); local poller = require "prosody.util.poll" local EEXIST = poller.EEXIST; @@ -1143,6 +1144,19 @@ return quitting; end +local hook_signal; +if have_signal and signal.signalfd then + local function dispatch(self) + return self:on("signal", signal.signalfd_read(self:getfd())); + end + + function hook_signal(signum, cb) + local watch = watchfd(signal.signalfd(signum), dispatch); + watch.listeners = { onsignal = cb }; + return watch; + end +end + return { get_backend = function () return "epoll"; end; addserver = addserver; @@ -1168,6 +1182,7 @@ set_config = function (newconfig) cfg = setmetatable(newconfig, default_config); end; + hook_signal = hook_signal; tls_builder = function(basedir) return sslconfig._new(tls_impl.new_context, basedir)